Internet Utility

What Is an API and How Do Developers Use It in Projects?

An API isn't a "bridge" or a "waiter"—it's a contract. Here's what that actually means in code: requests, keys, errors, and when to build it yourself.

What Is an API and How Do Developers Use It in Projects?

Someone asks me this at least once a month: "So, what actually is an API?" And every time, I watch myself reach for the same tired answer. "It's a bridge. It's a waiter in a restaurant." Then I see the person's eyes glaze over, because a waiter analogy never once helped anyone write a single line of working code.

An API—Application Programming Interface—is simply a contract that lets one piece of software ask another piece of software to do something, without either of them knowing how the other is built inside. That's the whole idea. The rest is detail. And the detail is where most tutorials stop, which is exactly where things get useful. If you want to use APIs in real projects, you don't need a metaphor. You need to know what a request looks like, where your key goes, what happens when the service says no, and when you should walk away and build the thing yourself.

That last part is where I've lost the most time. So let's talk about all of it.

Key Takeaways

  • An API is a defined contract—URL, method, expected inputs, expected outputs—not a mysterious black box.
  • Developers consume APIs in code, using a library that sends an HTTP request and parses the response (usually JSON).
  • Your API key is a secret. It belongs in an environment variable, never in code you commit to a repository.
  • Most real-world pain comes from error handling, rate limits, pagination, and auth—not from the first successful call.
  • ChatGPT itself is not an API. It's a product that developers reach through an API.
  • Choosing a third-party API vs. building your own comes down to cost, control, and how central the feature is to your product.

What is an API, really, once you strip the metaphors

An API is an interface, and the word "interface" is doing real work there. A user interface is what a human clicks. An application programming interface is what another program calls. Same principle, different audience.

The contract has four parts you'll meet on day one:

  • The endpoint—a URL that represents a resource, like https://api.example.com/v1/weather
  • The method—usually GET to read, POST to create, PUT or PATCH to update, DELETE to remove
  • The inputs—query parameters, headers, or a request body
  • The response—a status code plus a payload, almost always JSON in 2026

Why the abstraction matters more than the definition

Here's the thing nobody says clearly enough: the value of an API isn't that it lets software talk. It's that it lets software talk without the two sides being rebuilt whenever one of them changes. The weather service can rewrite its entire database layer, move to a new data center, change its caching strategy—and your code keeps working, because the contract didn't move. That separation is the entire point. The interface is stable; the implementation behind it is free to churn.

That stability is also why the waiter analogy fails. A waiter takes your order and walks to the kitchen. An API takes a request and hands back a response—but the kitchen can be in a different country, owned by a different company, and completely invisible to you. You don't get to peek. You're not supposed to.

Is an API just a JSON?

No, and this confuses people more than it should. JSON is a format—a way of writing structured data as text. An API is the arrangement that delivers that data and defines what you're allowed to ask for. You can have an API that returns XML, plain text, an image, or a binary file. JSON is just what most modern APIs settled on because it's readable by humans and trivial to parse in almost any language. The JSON you receive is the result of a call. It isn't the call itself.

How developers actually use APIs in projects

The first call is easy. I want to be honest about that, because the tutorials make it look hard and the hard parts look easy. A working request is maybe four lines of code. The trouble arrives the second you ship it to real users.

How developers actually use APIs in projects

From a first call to something you can ship

Say you're building a dashboard and you need exchange rates. You'd write something like this in JavaScript:

  • Store your key in an environment variable—process.env.RATES_API_KEY—never in the source file
  • Send a GET request to the endpoint with your key in an Authorization header
  • Check the status code before touching the body. A 200 with empty data is not success
  • Parse the JSON, and validate that the fields you expect are actually there
  • Handle the failure cases: timeout, 429 (too many requests), 401 (bad key), 500 (their problem)

That list is the difference between a demo and a feature. In fetch() in JavaScript, or requests in Python, the call itself is one line. Everything around it is where the work lives.

I'll admit something: the first time I wired a payment API into a checkout flow, I wrote the happy path in about twenty minutes and then spent two days on retries, idempotency keys, and what to show the user when the provider returned a 503 mid-transaction. The tutorial ended where my work began.

Authentication, secrets, and the mistake everyone makes once

Most APIs require a key, a token, or an OAuth flow. A Bearer token is the common pattern: you put it in a header and the server decides what you're allowed to do. The key is not a password you type—it's a credential your code carries, and it must be protected accordingly.

The mistake nearly every developer makes exactly once is committing that key to a repository. I did it in 2023. A scraping key, nothing dramatic, but it was public for about forty minutes before I noticed. I rotated it immediately, and I've kept every credential in environment files since. If you take one operational lesson from this article, take that one.

The second mistake is assuming a key with full permissions is convenient. It isn't—it's a liability. Scope keys to only what the project needs. When one leaks, the blast radius is the difference between an inconvenience and an incident.

When to consume an API, and when to build your own

This is the decision that separates developers who ship from developers who spend three weeks reimplementing an email validator. There's a clear rule of thumb I've come to trust.

When to consume an API, and when to build your own

Consume a third-party API when the capability is a commodity—payments, email delivery, maps, authentication, SMS. You will never out-engineer Stripe at payments. You shouldn't try.

Build your own when the capability is your product's core. If your entire value proposition is how you rank search results, then renting someone else's ranking engine means you're renting your differentiator. That's a business problem disguised as a technical one.

The gray zone—and it's a wide one—is everything in between. Logging, analytics, internal tooling. Here I lean toward buying, because the maintenance cost of a homegrown solution compounds silently. You write it once and maintain it forever.

How to evaluate an API before you commit

Five things to check before you write a line of integration code:

  1. Documentation quality. If the docs don't show a full request and a full response, that's a warning sign, not a nuance
  2. Rate limits. A free tier of 100 calls a day is a toy. Know your ceiling before you build on it
  3. Pricing at scale. The cost at your first 1,000 users is not the cost at your first 100,000
  4. Error semantics. Do they return meaningful status codes, or a 200 that secretly contains an error message?
  5. What happens on their side when things break. Look for a status page and a history of uptime. Vague promises are not an SLA

That fifth one matters more than people admit. I once built a feature around an API that had no status page and no published incident history. It went down for six hours on a Saturday with no notice to anyone. We had no fallback, no alert, and no way to tell our users anything except "it's broken." We replaced it within the month.

Aspect Consume a third-party API Build your own
Time to first working version Hours Days to weeks
Ongoing maintenance Their responsibility Yours, indefinitely
Cost model Per call, per seat, or per month Engineering time plus infrastructure
Control over behavior Limited to what the contract exposes Complete
Failure mode You depend on their uptime and their decisions You own the outage, but you can fix it

Common questions I get asked

How to use APIs in projects?

In practice, you install a client library or use your language's built-in HTTP tools, store your credentials in environment variables, wrap each call in error handling, and treat every response as untrusted until you've validated it. The pattern is the same whether you're pulling weather data or processing payments: authenticate, request, check the status, parse, and handle failure. The complexity scales with how critical the call is, not with the API itself.

Can you give me an example of an API?

Yes—a concrete one. Say you want the current temperature in Lisbon. You send a GET request to a weather service's endpoint, passing the city and your API key. The service returns something like {"city":"Lisbon","temp_c":21,"condition":"cloudy"}. You didn't measure the temperature. You didn't build a weather station. You asked a question in a format the service agreed to answer, and it replied with data you can now display. That exchange—request, contract, response—is an API at work.

Is chatgpt an API?

ChatGPT is not an API. It's a product—the chat interface you open in a browser or an app. Behind that product, the model is reachable through an API, and that's how developers integrate language models into their own tools, apps, and internal workflows. Think of it this way: the chat window is for people, the API is for programs. Same underlying capability, two different doors. When a company automates document summarization at scale, it isn't opening a chat window thousands of times. It's calling the API.

Where this leaves you

The waiter metaphor will keep circulating, and it will keep failing, because it describes the shape of an API without giving you anything to build with. What actually helps is unglamorous: a key in an environment variable, a status code you check, a failure path you handle before you need it, and a clear-eyed decision about whether the capability you're renting is a commodity or your edge.

Here's the part I find genuinely interesting. Every API you consume is a bet—that the provider will stay reliable, keep their contract stable, and price the thing in a way that still works when you're ten times bigger. Most of those bets pay off. The ones that don't cost you a weekend. So the next time someone offers you the waiter analogy, ask them instead: what happens when the kitchen closes without telling you? That question will teach you more about APIs than any metaphor ever will.

Lloyd Ellery

Lloyd Ellery

Lloyd Ellery is a seasoned cybersecurity professional whose expertise spans network security, penetration testing, incident response, and cryptography. He has helped organizations strengthen their digital defenses through hands-on assessments, rapid incident handling, and practical security guidance. A clear communicator and lifelong learner, Lloyd is dedicated to advancing the field and mentoring the next generation of security practitioners.

See all articles →

Related articles