8 API Laws of Senior Backend Developer — Transcript
Full transcript
- 0:00Let's look at eight REST API patterns
- 0:02that can make your APIs easier to
- 0:03understand, easier to integrate, and
- 0:06easier to maintain. Number one, design
- 0:09around resources, not actions. Here's a
- 0:12common API design mistake. You see
- 0:14endpoints like get users, create order,
- 0:17and delete product. At first, these seem
- 0:20perfectly understandable, but the URL is
- 0:22now describing the action, while HTTP is
- 0:26already designed to describe the action.
- 0:28A cleaner design is to use users,
- 0:31orders, and products as resources and
- 0:32let get, post, and delete describe what
- 0:35you're doing with them. This becomes
- 0:37especially useful as the API grows
- 0:39because the same resource can support
- 0:40multiple operations without inventing a
- 0:43different URL for every action. For
- 0:45example, an order can be retrieved,
- 0:48replaced, or deleted using the
- 0:49appropriate HTTP method. The important
- 0:52idea is simple. Let the URL identify the
- 0:55resource and let the HTTP method
- 0:57describe the operation.
- 0:59Number two, make your URLs predictable.
- 1:03Here's another thing that looks small
- 1:04but makes a huge difference. Consistency
- 1:07in resource naming. Suppose one part of
- 1:10your API uses user, another uses
- 1:12customers, and another uses customer
- 1:14profiles. The individual endpoints might
- 1:17all work, but now every developer has to
- 1:20remember the naming rules. A better API
- 1:23follows a predictable structure.
- 1:25Collections use consistent resource
- 1:27names such as users, orders, and
- 1:29products. And a specific resource can
- 1:31then be accessed using its identifier.
- 1:33For multi-word resources, choose one
- 1:36convention and use it everywhere. The
- 1:38exact convention matters less than
- 1:39consistency because a developer
- 1:41shouldn't have to guess how your API is
- 1:43structured. A predictable API needs
- 1:46fewer instructions.
- 1:47Number three, use HTTP methods for their
- 1:50actual purpose. Let's say you want to
- 1:53update a user. One API uses post,
- 1:56another uses put, another uses patch.
- 1:59All three might technically work, but
- 2:02now the client has to understand your
- 2:03custom rules instead of relying on
- 2:06standard HTTP semantics. Get should
- 2:09retrieve data without changing the
- 2:10resource.
- 2:12Post is commonly used to create a new
- 2:13resource or trigger processing that
- 2:15doesn't fit a straightforward resource
- 2:17update.
- 2:18Put is generally used when you're
- 2:20replacing the representation of a
- 2:21resource.
- 2:23Patch is for partial updates. And delete
- 2:25removes a resource.
- 2:27There's also an important concept here.
- 2:29Idempotency.
- 2:30If you send the same get request five
- 2:32times, you should get the same kind of
- 2:34effect as sending it once.
- 2:36The same general idea applies to put and
- 2:38delete. You can send the request again
- 2:40without repeatedly creating new effects.
- 2:43Post is different. Sending the same
- 2:45create request twice may create two
- 2:47resources.
- 2:48This matters because networks fail,
- 2:50clients retry, and timeouts happen. Your
- 2:53API should behave predictably when
- 2:55requests are repeated. So, don't choose
- 2:57HTTP methods just because they make the
- 3:00endpoint work. Choose them according to
- 3:02their intended semantics. Number four,
- 3:05make status codes useful.
- 3:07Here's an API response that causes
- 3:09problems.
- 3:10You return 200 OK, but the response body
- 3:13says that the operation failed because
- 3:15the product wasn't found. The HTTP
- 3:18response says success, while the body
- 3:21says failure. Now, the client has to
- 3:23inspect two different places to
- 3:25understand what happened. That's
- 3:26unnecessary. Use HTTP status codes to
- 3:29communicate the high-level result. A
- 3:31successful read might return 200. A
- 3:34successfully created resource can return
- 3:36201.
- 3:38An accepted request that will finish
- 3:39asynchronously can return 202.
- 3:42A successful operation without a
- 3:44response body can return 204.
- 3:47And errors should communicate what
- 3:48actually happened. You can use 400 for
- 3:51an invalid request, 401 when
- 3:54authentication is missing or invalid,
- 3:56403 when the client is authenticated but
- 3:59doesn't have permission, 404 when the
- 4:01requested resource doesn't exist, 409
- 4:04when the request conflicts with the
- 4:05current state, 422 when the request
- 4:08fails business validation, and 429 when
- 4:10the client is sending too many requests.
- 4:13The important thing isn't memorizing
- 4:15every status code. It's making the
- 4:17response understandable without
- 4:18inventing your own error protocol on top
- 4:21of HTTP.
- 4:23Use the status code to tell the client
- 4:24what happened.
- 4:26Number five, keep errors consistent.
- 4:29Status codes tell you the category of
- 4:30the failure, but the client often needs
- 4:32more information. Compare an error that
- 4:34simply says something went wrong with a
- 4:36structured response that provides an
- 4:38error code, a useful message, and the
- 4:40status.
- 4:41The second response is much easier for
- 4:43both humans and software to work with.
- 4:46The client can display the message, the
- 4:48application can react to the error code,
- 4:50and developers can investigate the
- 4:52problem. For validation failures, the
- 4:54API can also return exactly which fields
- 4:56need attention instead of simply saying
- 4:59invalid request. The exact format can
- 5:01vary between systems.
- 5:03The important thing is that errors
- 5:04should be structured and predictable.
- 5:07Your API shouldn't make clients guess
- 5:08what went wrong. Number six, don't put
- 5:11everything into the URL path. Here's
- 5:14another common pattern. You start with a
- 5:16products endpoint, then you add a
- 5:18category to the path, then stock status,
- 5:21then price, then search, then sorting.
- 5:24Eventually, the URL starts becoming
- 5:26difficult to manage.
- 5:27For filtering and optional criteria,
- 5:30query parameters are usually a better
- 5:31fit. The path identifies the resource,
- 5:34while the query parameters refine the
- 5:36result. But don't use query parameters
- 5:38to invent actions.
- 5:40A request that uses a get operation but
- 5:42adds something like an action equals
- 5:44delete parameter is confusing because
- 5:47the HTTP method in the URL no longer
- 5:51clearly communicate what's happening.
- 5:53Keep the responsibility clear.
- 5:55Paths identify resources.
- 5:57Query parameters refine them. HTTP
- 6:01methods describe the operation.
- 6:03Number seven, treat API changes
- 6:05carefully.
- 6:06APIs don't stay unchanged forever.
- 6:09A response that looks perfect today
- 6:10might need to change 6 months from now.
- 6:13Maybe you need to add new fields.
- 6:15Maybe the response structure needs to
- 6:17change.
- 6:18Maybe an existing field has the wrong
- 6:20meaning.
- 6:21The dangerous part is making a breaking
- 6:23change without thinking about existing
- 6:25clients.
- 6:26Suppose an earlier version returns a
- 6:28simple price field. And later, you want
- 6:30to replace it with a richer pricing
- 6:32structure.
- 6:33That isn't just another field. The
- 6:35structure has changed, and existing
- 6:37clients may break. So, first ask whether
- 6:40the change actually needs a new version.
- 6:42Adding a non-required field usually
- 6:44doesn't require breaking existing
- 6:46clients.
- 6:47Changing or removing existing behavior
- 6:49might. When you do need versioning, make
- 6:51the strategy obvious and consistent. You
- 6:54might use a version in the URL, a
- 6:56request header, or another established
- 6:58mechanism. The specific strategy matters
- 7:01less than using one predictable approach
- 7:03and giving consumers a path to migrate.
- 7:06Good API evolution means existing
- 7:08clients don't become collateral damage.
- 7:11Number eight, keep request and response
- 7:13formats consistent.
- 7:15Here's something developers
- 7:16underestimate. Imagine one endpoint
- 7:18returns created_at, another returns
- 7:21created_at, and another returns
- 7:23created_at.
- 7:25All three are valid, but now every
- 7:27client has to remember which convention
- 7:29applies to which endpoint. The same
- 7:31problem happens with dates, pagination,
- 7:33error responses, property names, and
- 7:36response structures. Pick conventions
- 7:38and stick to them. For example, use JSON
- 7:41consistently, choose one naming
- 7:43convention for JSON properties,
- 7:45standardize error responses, and make
- 7:48pagination and filtering work in a
- 7:49predictable way. The goal is not to
- 7:51create a giant API rulebook. The goal is
- 7:54to make the next endpoint look familiar.
- 7:57When a developer learns how one endpoint
- 7:58works, they should be able to make
- 8:00reasonable assumptions about the others.
- 8:02Consistency is one of the best features
- 8:04an API can have. And there's one more
- 8:07thing worth remembering. A lot of
- 8:09developers focus on whether an API
- 8:10technically follows REST. That's useful,
- 8:13but it's not the most important goal.
- 8:16Your API doesn't become good simply
- 8:17because it uses GET, POST, PUT, and
- 8:20DELETE. A good API is one that clients
- 8:23can understand without constantly
- 8:24checking documentation.
- 8:26The resource names make sense. The
- 8:28methods behave predictably. The status
- 8:31codes mean something. Errors have a
- 8:33consistent structure. Filters work the
- 8:35same way across endpoints, and changes
- 8:38don't unexpectedly break existing
- 8:39consumers. That's what makes an API
- 8:42pleasant to work with. So when you're
- 8:44designing your next REST API, don't
- 8:46start by creating endpoints one at a
- 8:48time. Start by defining the patterns.
- 8:51How will you name resources? How will
- 8:53you represent collections? How will
- 8:55filtering work? Which HTTP methods will
- 8:59you use? How will errors look? How will
- 9:02status codes be handled? How will the
- 9:04API evolve? And what conventions should
- 9:06every endpoint follow? Because once
- 9:09those rules are clear, building the API
- 9:11becomes much easier. A good REST API
- 9:14doesn't just return the right data. It
- 9:16makes the right way to use it obvious.
About this transcript
This page contains the full transcript of 8 API Laws of Senior Backend Developer by Cloud X Berry, generated from the public captions YouTube serves with the video. The transcript has 1,412 words across 255 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.