Tech Insights

REST API Design & Development

REST is not "JSON over HTTP." It is a set of constraints that, once you actually use them, make your API feel like it was designed by someone who respected your time.

REST API endpoints and HTTP methods diagram

TL;DR

REST isn't just JSON over HTTP; it's a set of constraints that make APIs predictable. Model resources as nouns, use HTTP methods and status codes for what they mean, paginate lists, return consistent errors, treat the contract as a promise with versioning and documentation, and let tools like OpenAPI make the right way easy.

On this page

The API that fights you

You have used the bad API. Every endpoint is a POST. Half of them are named getThing and the other half doThingAction. A “not found” comes back as 200 OK with {"success": false} buried in the body. The list endpoint returns all forty thousand rows in one breathless response. Errors arrive in three different shapes depending on which engineer wrote which route. Nothing is documented, and the one person who understood it left in March.

None of this is caused by hard problems. It is caused by an API built without a model - a pile of remote procedure calls wearing an HTTP costume. The fix is not more cleverness. It is the opposite: a small set of constraints, applied consistently, that let you stop making arbitrary decisions and let your consumers stop guessing.

REST is a discipline, not a library

When Roy Fielding described REST in his 2000 dissertation, he was not shipping a framework. He was naming the architectural style that already made the web scale to billions of documents. The core insight is that HTTP is not a dumb pipe you push JSON through. It is a uniform interface - a vocabulary of methods, URLs, status codes, and headers that every client, proxy, and cache on earth already understands.

The payoff of using that vocabulary as intended is leverage. A GET is safe, so a browser, a CDN, and a retrying proxy can all call it without fear. A PUT is idempotent, so a client that times out can simply try again. A 404 means the same thing in your API as in every other API, so a developer integrates without reading a manual. Every time you invent POST /getTaskById, you throw this leverage away and replace a global standard with a private one only you understand.

Think in resources

The mental shift that fixes most APIs is to stop thinking in functions and start thinking in resources - the nouns your domain cares about. A task. A collection of tasks. An invoice. A user’s profile. Each gets an address: /tasks for the collection, /tasks/42 for one item. You do not need a verb in that address, because HTTP already supplies the verb. GET /tasks/42 reads it. DELETE /tasks/42 removes it. POST /tasks creates a new one and answers 201 Created with a Location header pointing at the result.

This is not pedantry. It is what makes an API predictable. Once a developer learns how you handle tasks, they already know how you handle invoices, because the shape is the same. The uniformity is the feature. A good REST API is boring in exactly the way good infrastructure is boring: nothing surprises you.

The contract is a promise

Your representation - the JSON you send back - is a contract, and your consumers build against it. That reframes how you evolve the thing. Adding a new optional field is free; old clients ignore what they do not recognize. Renaming a field, changing its type, or making an optional input required is a betrayal of the promise, and it earns a version bump and a migration window. Teams that internalize “additive is cheap, destructive is expensive” ship for years on a single major version. Teams that do not break a partner integration every quarter.

The same respect applies to the unglamorous parts. Paginate every collection, because someday it will be huge. Pick one casing and one error shape and never deviate, because consistency is what lets a client write its parsing code once. Use the real status codes, because the status code is the first thing every HTTP library inspects and the last thing you want to lie about.

Tools make the right way the easy way

The encouraging part is that doing this well no longer requires heroics. Modern frameworks bend toward correctness. In Python, FastAPI lets you declare your request and response shapes as typed models; it then validates input at the boundary, returns a structured 422 when the input is wrong, and generates a complete, accurate OpenAPI specification from the same code that runs in production. Point a browser at /docs and you have interactive documentation that cannot drift from the implementation, because it is the implementation. Hand-written docs rot. Generated docs cannot lie.

That alignment - between the contract you publish, the code that enforces it, and the docs that describe it - is the quiet goal of all good API work. When those three agree, integration is an afternoon instead of a support ticket.

Where to start

You do not need to adopt every REST constraint to the letter; almost nobody implements full hypermedia, and that is fine. Start with the three that pay off immediately. Model your domain as resources. Give them clean, plural, noun-based URLs. Use HTTP’s methods and status codes to mean exactly what HTTP says they mean. Layer in pagination, a single error shape, validation, and generated docs, and you will have built something rare: an API that respects the time of the person on the other end. They will notice. They always do.

Key takeaways 5

  1. Bad APIs are usually remote procedure calls in an HTTP costume.
  2. Model resources as nouns and use HTTP methods as verbs.
  3. Return correct status codes and consistent error shapes.
  4. Paginate large lists and version breaking changes.
  5. Document the contract with OpenAPI.

Watch & learn

What Is REST API? Examples And How To Use It: Crash Course System Design #3ByteByteGo · YouTube

Frequently asked questions

What makes an API RESTful?

A RESTful API exposes resources through URLs, uses standard HTTP methods (GET, POST, PUT, PATCH, DELETE), returns appropriate status codes and is stateless between requests.

What status code should an API return when something isn't found?

404 Not Found. Returning 200 OK with an error inside the body hides failures from clients, caches and monitoring tools.

What is OpenAPI?

OpenAPI is a standard format for describing HTTP APIs, endpoints, parameters, schemas and responses, used to generate documentation, client SDKs and tests.

Tech InsightsProjects & Practice#rest#api-design#http#fastapi#openapi

Comments

No comments yet. Start the conversation.

Comments are reviewed before they appear. Be kind; one link max.

Go deeper with the free masterclass

Workshop, PDF handbook and curated resources for “REST API Design & Development”.

Open AL Academy ↗
Keep reading

Related articles