apis

APIs and REST โ€” how web applications communicate

๐Ÿ“˜ programming-academy · Part 11 of 15 · Module 5 · Professional Skills
A free, step-by-step course on buying, selling & trading domains. View the full series →
APIs and REST โ€” how web applications communicate
Key takeaways
  • APIs are how software systems communicate โ€” REST is the most common pattern using HTTP and JSON.
  • Use fetch or Axios to call APIs from JavaScript, and handle loading, error, and empty states.
  • Never expose API keys in frontend code โ€” keep secrets on the server.

APIs (Application Programming Interfaces) are how different software systems communicate with each other. When you check the weather on your phone, the app calls a weather API. When you pay online, the checkout calls a payment API. When you log in with Google, that is an OAuth API.

Understanding APIs and REST is essential for every developer โ€” whether you are building frontends that consume APIs or backends that provide them.

What APIs are and how REST works

An API defines a contract: 'send me a request in this format, and I will send you a response in that format.' REST (Representational State Transfer) is the most common API style:

  • Uses standard HTTP methods: GET (read), POST (create), PUT (update), DELETE (remove)
  • URLs represent resources: /api/products, /api/users/42
  • Data is exchanged as JSON (JavaScript Object Notation)
  • Stateless โ€” each request contains all the information needed to process it
  • Returns HTTP status codes: 200 (success), 404 (not found), 500 (server error)

Consuming APIs from the frontend

To call an API from JavaScript, use the fetch function or a library like Axios:

  • fetch('https://api.example.com/products') fetches a list of products
  • The response is JSON that you parse and display in the UI
  • Handle loading states, errors, and empty results gracefully
  • Use async/await for clean, readable asynchronous code
  • Respect rate limits โ€” most APIs limit requests per minute

API authentication and security

Most APIs require authentication to identify who is making requests:

  • API keys โ€” a secret string sent in a header. Simple but not user-specific.
  • JWT (JSON Web Tokens) โ€” a signed token containing user claims. Most common for web apps.
  • OAuth 2.0 โ€” delegated authorization (Login with Google/GitHub). Used for third-party access.
  • Session cookies โ€” server-side session with a cookie identifier. Traditional web apps.

Never expose API keys in frontend code โ€” they belong on the server. Use environment variables and server-side proxies.

When evaluating apis, start with the fundamentals: what problem it solves, who it serves, and how it compares to the alternatives buyers consider first.

Start with the fundamentals. Define who you are serving, the single outcome you want, and the budget you are comfortable committing before you compare any options.

A practical rule is to favour clarity over cleverness. The choice that is easiest to understand, spell, remember and act on tends to win over the long run.

Context changes the answer. What is optimal for a fast-moving startup is rarely optimal for an established brand, so weigh your own stage, market and ambitions.

Avoid the common mistakes: rushing the decision, copying competitors blindly, and ignoring the total cost of ownership beyond the very first year of use.

Think in terms of trade-offs rather than a single perfect answer. Every option trades memorability, cost, reach and flexibility in a slightly different mix.

Document your reasoning. Writing down why you chose one path makes it far easier to revisit the decision later and to explain it to partners and investors.

Test with real people. A quick check with a handful of your actual customers will surface problems that no amount of internal debate ever reveals.

Plan for growth. The option that fits today should still make sense when your audience, catalogue or team is several times larger than it is right now.

Finally, revisit the decision periodically. Markets, tools and best practices move quickly, and a choice that was ideal last year may deserve a fresh look today.

When evaluating apis, start with the fundamentals: what problem it solves, who it serves, and how it compares to the alternatives buyers consider first.

Start with the fundamentals. Define who you are serving, the single outcome you want, and the budget you are comfortable committing before you compare any options.

A practical rule is to favour clarity over cleverness. The choice that is easiest to understand, spell, remember and act on tends to win over the long run.

Context changes the answer. What is optimal for a fast-moving startup is rarely optimal for an established brand, so weigh your own stage, market and ambitions.

Avoid the common mistakes: rushing the decision, copying competitors blindly, and ignoring the total cost of ownership beyond the very first year of use.

Think in terms of trade-offs rather than a single perfect answer. Every option trades memorability, cost, reach and flexibility in a slightly different mix.

Document your reasoning. Writing down why you chose one path makes it far easier to revisit the decision later and to explain it to partners and investors.

Test with real people. A quick check with a handful of your actual customers will surface problems that no amount of internal debate ever reveals.

Plan for growth. The option that fits today should still make sense when your audience, catalogue or team is several times larger than it is right now.

Finally, revisit the decision periodically. Markets, tools and best practices move quickly, and a choice that was ideal last year may deserve a fresh look today.

When evaluating apis, start with the fundamentals: what problem it solves, who it serves, and how it compares to the alternatives buyers consider first.

Start with the fundamentals. Define who you are serving, the single outcome you want, and the budget you are comfortable committing before you compare any options.

A practical rule is to favour clarity over cleverness. The choice that is easiest to understand, spell, remember and act on tends to win over the long run.

Context changes the answer. What is optimal for a fast-moving startup is rarely optimal for an established brand, so weigh your own stage, market and ambitions.

Avoid the common mistakes: rushing the decision, copying competitors blindly, and ignoring the total cost of ownership beyond the very first year of use.

Think in terms of trade-offs rather than a single perfect answer. Every option trades memorability, cost, reach and flexibility in a slightly different mix.

Document your reasoning. Writing down why you chose one path makes it far easier to revisit the decision later and to explain it to partners and investors.

Explore Crypto Trading

Cryptocurrency trading is one of the fastest-growing financial markets โ€” open 24/7, globally accessible, and full of opportunity for those who learn the fundamentals first.

  • Trade spot, futures & copy-trading on one platform
  • Start with as little as $10 โ€” practice risk-free on the testnet
  • Built-in TradingView charts, grid bots & DCA tools

Free Crypto Trading Academy → ยท Domain Trading Academy →

Frequently asked questions

What is the difference between REST and GraphQL?

REST uses multiple endpoints (one per resource). GraphQL uses one endpoint where the client specifies exactly what data it needs. REST is simpler and more widely used. GraphQL is better when the frontend needs flexible, nested data without multiple round-trips.

How do I practice working with APIs?

Use public APIs: OpenWeatherMap (weather), JSONPlaceholder (fake data), PokéAPI (Pokémon data). Build a project that fetches data and displays it โ€” a weather app, a movie database, or a GitHub profile viewer.

Free Courses โ€” Learn New Skills

No sign-up · No fees · Learn at your own pace

Start Trading

Trade crypto and premium domains โ€” digital assets with real opportunities.

Find your name on Atom

DominantBrand curates the best premium, brandable names from Atom.com — the marketplace with a free AI appraisal, a USPTO trademark check, and secure escrow. Every listing even ships with a designed logo.

Browse Domains