Latest / CyberSecurity Summary / The Design of Web APIs, Second Edition
Transcript
- 0:00Speaker 1: Welcome to the deep dive. Today, we're jumping into something
- 0:03Speaker 1: that powers so much of our digital world but often
- 0:05Speaker 1: stays hidden, Web API design. Our main guide for this
- 0:08Speaker 1: is the second edition of the Design of Web APIs
- 0:11Speaker 1: by Arnoul Loray. It's described as taking you from well
- 0:15Speaker 1: novice to pro in building APIs that work well, are
- 0:18Speaker 1: easy to use, and importantly aren't a pain to deal with?
- 0:20Speaker 1: So why should you care about this? Simple? Really a
- 0:23Speaker 1: well designed API, it's like a secret startcut to making
- 0:26Speaker 1: things work efficiently, giving users great experiences. A bad one, though,
- 0:30Speaker 1: that's a recipe for frustration, crashes, slow apps, and just
- 0:34Speaker 1: piling up technical problems nobody wants to deal with. Have
- 0:37Speaker 1: you ever struggled with an apro website? Wondered why it
- 0:40Speaker 1: was so slow, or maybe crash or just felt confusing?
- 0:42Speaker 1: Often the root cause, buried deep down is poor API design.
- 0:46Speaker 2: That's exactly right, and the challenge we're really going to
- 0:48Speaker 2: unpack today is figuring out what goes into making an
- 0:51Speaker 2: API that one does the right job, two is actually
- 0:55Speaker 2: user friendly and works well with other systems. Three considers
- 0:59Speaker 2: all the real world constraints like security and performance, and
- 1:02Speaker 2: four is built using a process that keeps getting better.
- 1:06Speaker 2: It's a skill that applies everywhere, whether it's an internal
- 1:09Speaker 2: tool or a huge public platform.
- 1:11Speaker 1: Okay, let's back up a bit. What exactly is a
- 1:14Speaker 1: web API?
- 1:15Speaker 2: Fundamentally, fundamentally, it's a software interface. Think of it as
- 1:18Speaker 2: a way for different applications to talk to each other
- 1:21Speaker 2: over a network, mostly using HTTP, the language of the web.
- 1:24Speaker 1: So when my phone app gets new updates, that's an
- 1:27Speaker 1: API talking to the back end precisely.
- 1:29Speaker 2: Or when different server applications need to coordinate complex tasks
- 1:33Speaker 2: behind the scenes, APIs make that communication possible, and they're
- 1:36Speaker 2: not just single channels. One API can offer many different
- 1:40Speaker 2: operations and many different apps can use that same API.
- 1:43Speaker 2: We should probably also mention the types private for internal use,
- 1:47Speaker 2: partner for specific collaborators, and public APIs for well everyone
- 1:52Speaker 2: and a key thing. Even private APIs might still be
- 1:54Speaker 2: accessible from the Internet. So design and security or just
- 1:57Speaker 2: as crucial there.
- 1:58Speaker 1: Right, which brings us square to why good design is
- 2:01Speaker 1: so critical. Often the best way to see that is
- 2:03Speaker 1: to look at the pain caused by bad design. The
- 2:06Speaker 1: book mentions things like cryptic or inconsistent naming, poor data organization,
- 2:10Speaker 1: maybe missing data or operations we've all been there, right,
- 2:14Speaker 1: I definitely remember hours spent trying to figure out why
- 2:16Speaker 1: a call failed, only getting back a totally unhelpful bad
- 2:20Speaker 1: request error. Just maddening.
- 2:22Speaker 2: Oh. Absolutely, it's a classic developer nightmare. Laurie uses this
- 2:27Speaker 2: brilliant analogy in the book The Kitchen Radar. Imagine a microwave,
- 2:31Speaker 2: but instead of normal controls, it just has one button
- 2:34Speaker 2: bag and you have to hold it down to heat things,
- 2:36Speaker 2: figuring out the timing yourself.
- 2:38Speaker 1: Huh, so you have to become a magnetron expert just
- 2:41Speaker 1: to warm up coffee exactly.
- 2:42Speaker 2: It sounds absurd, but it perfectly mirrors how some poorly
- 2:46Speaker 2: designed APIs force developers to understand obscure internal details, and
- 2:51Speaker 2: the impact is huge. Developers write fragile, complex code, end
- 2:55Speaker 2: users get crashes, confusing errors, maybe workflows that make.
- 2:58Speaker 1: No sense, which leads to frustration, maybe canceling subscriptions or
- 3:02Speaker 1: just switching to a competitor.
- 3:03Speaker 2: Right, and for the company providing the API, it means
- 3:06Speaker 2: rising technical debt, wasted engineer time, production problems, security risks,
- 3:11Speaker 2: even lost revenue. It's bad for everyone.
- 3:13Speaker 1: Okay, So if the kitchen radar is what we want
- 3:15Speaker 1: to avoid, how do we actually build something good? How
- 3:18Speaker 1: does this design process fit into actually building software?
- 3:21Speaker 2: Well? API design sits in that crucial space between figuring
- 3:25Speaker 2: out what's needed and actually starting to write the code.
- 3:28Speaker 2: It's a process. You move through stages like identify API capabilities,
- 3:33Speaker 2: then you design the programming interface. Then you need to
- 3:36Speaker 2: describe it clearly, and finally enrich those design documents.
- 3:40Speaker 1: Okay, and the book breaks this down conceptually into layers.
- 3:43Speaker 2: Yeah, four conceptual layers, each tackling a different aspect of
- 3:45Speaker 2: the problem. The helpful way to think about it. First,
- 3:48Speaker 2: a versatile API design that does the right job. This
- 3:52Speaker 2: is about meeting the real user needs, hiding the messy
- 3:55Speaker 2: internal stuff, and making it usable in ways you might
- 3:57Speaker 2: not even anticipate yet. Think about a so network API.
- 4:01Speaker 2: Maybe today it serves the mobile and web apps, but
- 4:04Speaker 2: a well designed versatile one could potentially power a smart
- 4:07Speaker 2: fridge integration tomorrow without needing a rewrite.
- 4:10Speaker 1: Interesting future proofing, almost what's next.
- 4:13Speaker 2: Second layer, an API design that is user friendly and interoperable,
- 4:17Speaker 2: making it easy to understand, easy to use, and ensuring
- 4:20Speaker 2: it plays nicely with other systems. Common sense, but crucial
- 4:24Speaker 2: makes sense. Third third, an API design that considers constraints.
- 4:29Speaker 2: This is where you really integrate things like security performance,
- 4:33Speaker 2: the specific context it operates in, and how you'll handle
- 4:36Speaker 2: future changes. And the final layer, finally, a reasoned and
- 4:40Speaker 2: continuously improving API design process. This is about how you
- 4:44Speaker 2: make decisions consistently based on good principles and always looking
- 4:48Speaker 2: for ways to improve.
- 4:49Speaker 1: Okay, let's dive into that first layer. Then identifying capabilities.
- 4:52Speaker 1: Where do you even start?
- 4:54Speaker 2: You start by analyzing the user needs. This often begins
- 4:57Speaker 2: pretty vague, like we need a social network, you.
- 5:00Speaker 1: Know, right, very high level exactly.
- 5:02Speaker 2: But you need to quickly get more specific. What does
- 5:04Speaker 2: that actually mean for users? Maybe it's allow users to
- 5:07Speaker 2: tag friends in a photo. The key is expressing these
- 5:11Speaker 2: needs in plane language first, something everyone involved can understand.
- 5:14Speaker 1: So how do you break those big needs down systematically?
- 5:18Speaker 2: Decomposition is key breaking down those use cases into small,
- 5:21Speaker 2: manageable steps. The book introduces a tool called the API
- 5:25Speaker 2: Capabilities Canvas for this. You work through it twice. Essentially, First,
- 5:29Speaker 2: you map out the happy path, the way things should
- 5:31Speaker 2: work ideally, the normal flow right. Then you go back
- 5:34Speaker 2: and figure out all the alternative paths. There are edge cases,
- 5:38Speaker 2: and importantly, the failure scenarios what happens when things go wrong,
- 5:42Speaker 2: and doing this often reveals overlaps, like the step upload
- 5:47Speaker 2: of photo might be needed for sharing a status and
- 5:50Speaker 2: for changing your profile picture, same underlying capability, different context.
- 5:54Speaker 1: Okay, so you've identified these capabilities, how does that translate
- 5:57Speaker 1: into the actual interface a developer interact with the programming interface?
- 6:01Speaker 2: Those capabilities generally map onto two core concepts, resources and actions.
- 6:06Speaker 2: A resource is like a now a high level concept
- 6:09Speaker 2: like product, user, order and actions are the verbs what
- 6:12Speaker 2: you can do to those resources get product, create, order, update,
- 6:16Speaker 2: user search products.
- 6:17Speaker 1: And how are those represented in a typical web API
- 6:20Speaker 1: using HTTP.
- 6:21Speaker 2: That's where the standard AGTP methods come in. Get to retrieve,
- 6:24Speaker 2: post to create, put to replace, patch to partially update,
- 6:28Speaker 2: and delete to remove. You combine these methods with resource paths,
- 6:31Speaker 2: which are like addresses for your resources products for the
- 6:35Speaker 2: collection products one, two, three for a specific one.
- 6:37Speaker 1: So the path structure shows relationships like users, four, five, six,
- 6:41Speaker 1: orders exactly.
- 6:42Speaker 2: It describes hierarchy. But, and this is crucial, the paths
- 6:47Speaker 2: should not directly mirror how your data is stored internally.
- 6:51Speaker 2: You want to hide the provider's perspective and focus on
- 6:53Speaker 2: the consumer's needs.
- 6:55Speaker 1: That keeps it flexible, right decoupling. Now, when a developer
- 6:58Speaker 1: makes a request, where does the input data actually go?
- 7:02Speaker 2: Good question? There are standard places within an HTTPU request.
- 7:07Speaker 2: Path parameters are usually for identifiers like that product's one
- 7:10Speaker 2: twenty three. The one to twenty three is a path parameter.
- 7:12Speaker 1: Okay, it makes sense.
- 7:13Speaker 2: Query parameters live after the question mark in the URL.
- 7:16Speaker 2: They're great for things that modify the request like filter, status, published, sorting,
- 7:20Speaker 2: or pagination in any ear, you don't want to force
- 7:22Speaker 2: these into the path as they're often optional.
- 7:24Speaker 1: Got it? What else?
- 7:25Speaker 2: Headers carry metadata about the request itself, things like authentication tokens,
- 7:30Speaker 2: authorization bearer, or specifying the content type being sent, content type, dot, application, adjacent.
- 7:36Speaker 1: And the main data for creating something new.
- 7:38Speaker 2: That usually goes in the request body, especially for post
- 7:41Speaker 2: put and patthch requests, where you're sending a representation of
- 7:45Speaker 2: the resource.
- 7:46Speaker 1: Okay, so that's input. What about the output? How does
- 7:48Speaker 1: the API tell the consumer what happened?
- 7:51Speaker 2: Primarily through HTDP status codes, those familiar three digit.
- 7:54Speaker 1: Numbers like two hundred to ok or four or four
- 7:57Speaker 1: not found exactly.
- 7:58Speaker 2: They fall into classes two XX means success. Four x
- 8:02Speaker 2: means the client messed up, bad input, not authorized, et cetera.
- 8:05Speaker 2: Five xx means something went wrong on the server side.
- 8:07Speaker 2: Common success codes include two oh one created when you
- 8:10Speaker 2: successfully make a new resource, or two oho four to
- 8:13Speaker 2: no content after a successful deletion where there's nothing to return,
- 8:16Speaker 2: and errors four hundred to bout amount. Bad request is
- 8:19Speaker 2: common for invalid input, four to one, unauthorized, four oh
- 8:22Speaker 2: three forbidden, four hundred for four and not found. They
- 8:25Speaker 2: all signal specific client side issues. Crucially, successful responses often
- 8:29Speaker 2: return data in the response body, and for creations a
- 8:32Speaker 2: two oh one you should usually include a location header
- 8:35Speaker 2: pointing to the URL of the newly created resource.
- 8:37Speaker 1: Makes sense, Let's shift to the data itself. How do
- 8:40Speaker 1: you actually define the structure of the information being passed
- 8:42Speaker 1: back and forth.
- 8:43Speaker 2: That's where data modeling comes in, usually using Jason's schema
- 8:47Speaker 2: within an open API specification. It gives you a formal
- 8:50Speaker 2: way to describe the data structure, types, constraints, everything.
- 8:54Speaker 1: And the book suggests a particular approach.
- 8:57Speaker 2: Yeah. It emphasizes the idea of starting with a theore,
- 9:00Speaker 2: medical or complete resource model. Think of your product resource
- 9:04Speaker 2: to find everything it could possibly contain all the details
- 9:07Speaker 2: the maximal view. Right then that complete model becomes the
- 9:10Speaker 2: source for deriving other more specific models you'll actually use
- 9:13Speaker 2: in the API, like summarize models for when you return
- 9:17Speaker 2: a list. You don't need every detail to summary minimal
- 9:20Speaker 2: models that might just contain the ID maybe for linking
- 9:23Speaker 2: between resources. Creation models for PST requests often a subset
- 9:28Speaker 2: of the full model only the fields needed to create it.
- 9:31Speaker 2: Same for put replacement.
- 9:33Speaker 1: And PCCh for updates.
- 9:35Speaker 2: Exactly, modification models for PTH, where typically all fields are
- 9:39Speaker 2: optional because you're only changing some things. This approach brings
- 9:42Speaker 2: a lot of consistency. You're not defining similar structures over
- 9:45Speaker 2: and over again.
- 9:46Speaker 1: That leads nicely into data user friendliness. It's not just
- 9:50Speaker 1: about structure, but the content of the data, right.
- 9:52Speaker 2: Absolutely, it's about selecting data that's genuinely relevant and helpful
- 9:56Speaker 2: to the consumer, not just dumping everything from your database.
- 10:00Speaker 2: The idea here is providing supporting data or even process data.
- 10:04Speaker 1: What's an example of that.
- 10:06Speaker 2: The book gives a great banking API example. Instead of
- 10:09Speaker 2: just giving the raw count balance and the overdraft limit
- 10:12Speaker 2: and forcing the consumer to calculate if a purchase is possible.
- 10:15Speaker 1: You could provide a calculated safe to spend amount exactly
- 10:19Speaker 1: that directly answers the user's likely question, reduces the chance
- 10:22Speaker 1: of errors on their side, and makes the API much
- 10:25Speaker 1: easier to use.
- 10:27Speaker 2: It's about anticipating needs.
- 10:29Speaker 1: That's smart. What else contributes to user friendly data?
- 10:32Speaker 2: Using well known or standard identifiers whenever possible, Like use
- 10:36Speaker 2: an IBAND for a bank account if that's the standard.
- 10:38Speaker 2: Don't just expose your internal database ID.
- 10:40Speaker 1: Makes sense less look up needed right, and use.
- 10:42Speaker 2: Human readable codes instead of account type one. Use account
- 10:45Speaker 2: type checking. It's immediately understandable, and of course, be super
- 10:50Speaker 2: consistent with your atomic data types and formats. Always use
- 10:53Speaker 2: ISO eighty six to ZHO one for dates and times
- 10:56Speaker 2: for example, no surprises.
- 10:57Speaker 1: Okay, And how about organizing the data within a response?
- 11:01Speaker 1: Structuring it well?
- 11:02Speaker 2: Good structure is key. Use objects to group related feels together,
- 11:06Speaker 2: like instead of overdraft limit and overdraft, use floating around
- 11:10Speaker 2: group them in an overdraft facility.
- 11:11Speaker 1: Object keeps things tidy.
- 11:13Speaker 2: Yeah, and use a raise for lists of similar items,
- 11:17Speaker 2: like a balance's array if an account can have multiple
- 11:20Speaker 2: currency balances. But there's a big caution here. Avoid embedding
- 11:24Speaker 2: large lists directly within a main resource response, especially if
- 11:28Speaker 2: those lists might need filtering or pagination.
- 11:30Speaker 1: Like putting all of a user's transaction history inside the
- 11:33Speaker 1: main user object exactly.
- 11:35Speaker 2: That's usually a bad idea. If you need to get transactions,
- 11:38Speaker 2: provide a dedicated operation like users one, two, three transactions
- 11:41Speaker 2: that supports pagination and filtering properly. Don't overload the primary resource.
- 11:45Speaker 1: That makes a lot of sense for performance too.
- 11:47Speaker 2: Absolutely, and the golden rule overarting all of this data
- 11:51Speaker 2: design is consistency, naming, conventions, data types. How you structure
- 11:56Speaker 2: objects in a raise keep it consistent across the entire API.
- 12:00Speaker 2: That predictability makes the API dramatically easier and faster for
- 12:03Speaker 2: developers to learn and use.
- 12:05Speaker 1: Right, Okay, let's pivot to constraints. Starting with a big
- 12:08Speaker 1: one security, How does API designed influence security massively?
- 12:13Speaker 2: Security isn't something you bolt on at the end. It
- 12:16Speaker 2: needs to be baked into the design choices you make
- 12:18Speaker 2: from the start. Your design is part of your security posture.
- 12:21Speaker 1: So how do you design for security?
- 12:23Speaker 2: A fundamental principle is minimizing the API surface area. Only
- 12:27Speaker 2: expose the operations and the data that are absolutely necessary.
- 12:31Speaker 2: Really challenge requests for sensitive data. Do we really need
- 12:34Speaker 2: to expose the user's exec GPS coordinates or their phone number?
- 12:37Speaker 1: If so, why and if you do need it.
- 12:39Speaker 2: Maybe can transform it, perhaps return a city or region
- 12:41Speaker 2: instead of precise coordinates, or maybe split very sensitive operations
- 12:45Speaker 2: off into a separate API that has much tighter access controls.
- 12:49Speaker 2: Less exposure means less risk.
- 12:51Speaker 1: Speaking of access control, how does that work in API design?
- 12:54Speaker 1: You mentioned scopes earlier.
- 12:55Speaker 2: Yes, scopes are a common mechanism for authorization. They define permissions.
- 13:00Speaker 2: You might have a red profile scope and a separate
- 13:02Speaker 2: update profile scope, or maybe a transfer money scope.
- 13:05Speaker 1: So the API consumer requests certain scopes and the API
- 13:08Speaker 1: checks if they have them before allowing an operation.
- 13:11Speaker 2: Exactly, and scopes can be defined that different levels of
- 13:14Speaker 2: granularity per operation, per resource type, maybe even based on
- 13:18Speaker 2: the specific user role or the application making the call.
- 13:21Speaker 2: Depends on your security requirements.
- 13:23Speaker 1: Okay, what about protecting the data itself? Data integrity?
- 13:28Speaker 2: Several design aspects contribute here. First, using HTTP methods correctly
- 13:33Speaker 2: get should be safe, no side effects. Put in delete
- 13:36Speaker 2: should be idempatant. Running them multiple times as the same
- 13:39Speaker 2: effect as running them.
- 13:40Speaker 1: Once prevents accidental double charges or double deletions. If a
- 13:43Speaker 1: request is retried precisely.
- 13:45Speaker 2: You can also prevent malicious or accidental request replays by
- 13:49Speaker 2: requiring an adempotency key header. For non adempitent operations like PFOST,
- 13:54Speaker 2: the server uses this key to ensure it only processes
- 13:56Speaker 2: the request once AH and for updates. Condition updates are vital.
- 14:01Speaker 2: Imagine two users trying to update the same customer record
- 14:04Speaker 2: at the same time.
- 14:05Speaker 1: One might overwrite the other's changes without realizing it right.
- 14:09Speaker 2: Using E tag hitters, which represent the version of the
- 14:12Speaker 2: resource and if match hitters, which say only perform this
- 14:16Speaker 2: update if the E tag matches what I last saw
- 14:19Speaker 2: prevents this lost update problem.
- 14:22Speaker 1: Got it? That seems really important for data consistency. What
- 14:26Speaker 1: about handling errors securely?
- 14:28Speaker 2: Yes, secure air handling is crucial. You need to give feedback,
- 14:32Speaker 2: but not too much information that could help an attacker.
- 14:35Speaker 2: Use standard machine readable error formats like problem details for httpapis.
- 14:41Speaker 2: This provides structure type, title, status, detail, instant It.
- 14:44Speaker 1: Avoid generic unhelpful messages like just error definitely.
- 14:48Speaker 2: But also return all validation errors at once if possible.
- 14:51Speaker 2: Don't make the consumer fix one thing, resubmit find another error.
- 14:54Speaker 2: Fix that. It's incredibly frustrating.
- 14:56Speaker 1: Yeah, that back and forth is terrible. Any other security
- 14:59Speaker 1: pitfalls and.
- 14:59Speaker 2: Design one big one. Sensitive data in URLs. Even with
- 15:04Speaker 2: HTTPS URLs, paths and query parameters can leak. They might
- 15:09Speaker 2: end up in browser history, server logs, referra headers, So.
- 15:13Speaker 1: Putting a password or credit card number in a query
- 15:15Speaker 1: parameter is a definite no.
- 15:17Speaker 2: No absolutely for anything sensitive, especially if it's being used
- 15:20Speaker 2: for searching or filtering. Strongly, consider using a post request
- 15:24Speaker 2: and putting these sensitive data securely in the request body instead.
- 15:28Speaker 1: Good tip. Okay, let's switch from security to another key constraint. Efficiency.
- 15:32Speaker 1: Why is this so important?
- 15:33Speaker 2: Efficiency benefits everyone? For consumers, it means faster apps, less
- 15:38Speaker 2: battery drain on mobile, lower data usage. For the API provider,
- 15:42Speaker 2: it means lower server costs, less strain on infrastructure, better scalability.
- 15:46Speaker 2: Small efficiencies can save a lot of money at.
- 15:48Speaker 1: Scale, So how do you design for efficiency? Caching seems
- 15:51Speaker 1: like an obvious one.
- 15:52Speaker 2: Cashing is huge. Using standard HTTP caching headers like cash
- 15:55Speaker 2: control tells downstream caches, browsers, CDNs proxies how long they
- 15:59Speaker 2: can use a response without.
- 16:01Speaker 1: Asking again, saves bandwidth and reduces load massively.
- 16:04Speaker 2: And even better is using conditional requests with ETag and
- 16:07Speaker 2: if none match, the client sends the ETag it has
- 16:10Speaker 2: for a resource. If the resource hasn't changed on the server,
- 16:14Speaker 2: the server just replies with a tiny three to four
- 16:17Speaker 2: not modified response without sending the data. Again super efficient.
- 16:21Speaker 1: Nice. What about reducing the end of data sent in
- 16:23Speaker 1: the first place?
- 16:24Speaker 2: Several techniques we mentioned Resource model selection earlier let consumers
- 16:29Speaker 2: ask for a summarized view if they don't need all
- 16:31Speaker 2: the details. Field selection is another, allowing consumers to explicitly
- 16:35Speaker 2: request only the fields they need, like dot field's name. Balance,
- 16:40Speaker 2: Why send data they're just going to ignore?
- 16:42Speaker 1: Good point.
- 16:42Speaker 2: Also look for redundant data. If the same piece of
- 16:45Speaker 2: information appears in many different responses, maybe centralize it in
- 16:48Speaker 2: its own resource or operation, and definitely prefer partial updates
- 16:52Speaker 2: using PTCH over full replacements with pet when possible, Sending
- 16:56Speaker 2: only the changed fields is much more efficient than sending
- 16:58Speaker 2: the entire resource representation.
- 17:00Speaker 1: Again right, the book mentioned two types of PTCH.
- 17:03Speaker 2: Yes, Jason merge patch is simpler, basically merging the provided
- 17:07Speaker 2: JSON into the existing resource. Jason patch is more powerful,
- 17:11Speaker 2: using explicit operations like ad remove, replace targeted at specific
- 17:16Speaker 2: parts of the Jason document. It's better for complex updates,
- 17:18Speaker 2: especially involving a raise.
- 17:20Speaker 1: Okay, what about handling large lists of items efficiently?
- 17:24Speaker 2: Pagination is essential, don't try to return thousands of items
- 17:27Speaker 2: in one go. Break it into pages.
- 17:29Speaker 1: Index based or cursor based.
- 17:31Speaker 2: Both have pros and cons Cursor based is generally more
- 17:34Speaker 2: robust against data changing while you're paginating. But the critical
- 17:38Speaker 2: design decision here is a default page size. The book
- 17:41Speaker 2: warns against huge defaults like ten thousand that can hammer
- 17:44Speaker 2: your database and the network. Choose a sensible default, maybe
- 17:48Speaker 2: twenty fifty or one hundred, and let consumers request more
- 17:51Speaker 2: if they really need it.
- 17:52Speaker 1: Sensible advice any other efficiency boosters.
- 17:55Speaker 2: Bulk operations can be great. Instead of making one hundred
- 17:58Speaker 2: separate API calls to create one hundred acas ounce, allow
- 18:00Speaker 2: a consumer to send a single request with all one
- 18:02Speaker 2: hundred much less network overhead.
- 18:04Speaker 1: But how do you handle errors in bulk operations? If
- 18:08Speaker 1: one fails?
- 18:09Speaker 2: That's the key design choice. Is it all or nothing
- 18:11Speaker 2: one failure fails the whole batch, or do you process
- 18:14Speaker 2: each one individually and return a mixed result. The each
- 18:18Speaker 2: TTP two O seven multi status response code is often
- 18:22Speaker 2: used for mixed results indicating success or failure for each
- 18:26Speaker 2: item in the batch.
- 18:26Speaker 1: Okay, and finally managing usage.
- 18:29Speaker 2: Right rate limiting. You need to control how frequently consumers
- 18:32Speaker 2: can call your API to protect your infrastructure from overload,
- 18:36Speaker 2: whether accidental or malicious, and crucially be transparent about it.
- 18:40Speaker 2: Use standard headers like rate limit limit, rate limit, remaining,
- 18:44Speaker 2: rate limit reset, or the older X rate limit versions
- 18:47Speaker 2: so consumers know the rules and can adjust their behavior.
- 18:50Speaker 1: Makes sense. Protect yourself, but let users know the limits exactly.
- 18:53Speaker 2: It's about fairness and stability. Now, beyond security and efficiency,
- 18:58Speaker 2: good API design has a consider the broader context that
- 19:01Speaker 2: operates in What are the specific needs or constraints of
- 19:04Speaker 2: this particular situation.
- 19:05Speaker 1: Can you give some examples of these contextual constraints?
- 19:08Speaker 2: Sure? Think about file handling. If you need to upload
- 19:11Speaker 2: a file along with some metadata, multipart form data is
- 19:13Speaker 2: a standard way or maybe Base sixty four encoding for
- 19:16Speaker 2: small files embedded in JSON, though that increases size.
- 19:20Speaker 1: What about really big files, uploading videos or something.
- 19:23Speaker 2: Yeah, for large files, hitting your main API gateway might
- 19:26Speaker 2: not be efficient or even possible due to size limits.
- 19:29Speaker 2: A common pattern is to use sign URLs your API
- 19:32Speaker 2: generates a temporary, secure URL, maybe pointing to cloud storage
- 19:36Speaker 2: like S three gives it to the client, and the
- 19:38Speaker 2: client uploads or downloads directly from storage by passing your
- 19:42Speaker 2: main API infrastructure for the bulk transfer.
- 19:44Speaker 1: Ah, that's clever, offloading the heavy lifting. What else?
- 19:48Speaker 2: Event notification Sometimes the consumer needs to know when something
- 19:52Speaker 2: happens immediately without constantly asking the API anything new.
- 19:56Speaker 1: Yet that's pulling right can be inefficient.
- 19:58Speaker 2: Very The alternative is web hoooks. The consumer provides a URL,
- 20:02Speaker 2: and your API calls their URL proactively whenever is specific
- 20:05Speaker 2: event occurs, like a new order, place to transaction completed.
- 20:09Speaker 2: Standard formats like cloud vents help make these web hoook
- 20:11Speaker 2: payloads consistent and understandable.
- 20:13Speaker 1: So the information flows the other way when needed. What
- 20:16Speaker 1: about tasks that just take a long time.
- 20:18Speaker 2: Long running operations, Yeah, like starting a complex data analysis
- 20:22Speaker 2: job or a simulation. The initial API call might return immediately,
- 20:26Speaker 2: maybe for the status urrol. Then the client has two options,
- 20:30Speaker 2: polling checking that status URL periodically until the job is done, or,
- 20:35Speaker 2: if supported, providing a callback URL similar to a webhook,
- 20:39Speaker 2: where your API will notify them once the long operation
- 20:42Speaker 2: is complete.
- 20:42Speaker 1: Choosing the right pattern depends on the use case, I
- 20:44Speaker 1: guess absolutely.
- 20:46Speaker 2: And this idea of choosing the right pattern extends to
- 20:48Speaker 2: the type of API itself. Rest Over HTTP is the
- 20:51Speaker 2: default for many webapis, and it's great for request response
- 20:54Speaker 2: interactions with resources, but it's not the only tool.
- 20:57Speaker 1: When might you choose something else.
- 20:59Speaker 2: If you need to stream data continuously from server to client,
- 21:01Speaker 2: maybe e Server sent Events SSE is better for real
- 21:04Speaker 2: time two way communication like a chat app. Web sockets
- 21:07Speaker 2: might be the answer. If you have mobile apps needing
- 21:09Speaker 2: very specific, flexible data combinations to avoid overfetching. Maybe graphic
- 21:13Speaker 2: cool makes senses a back end for front.
- 21:15Speaker 1: End layer and for internal micro services.
- 21:18Speaker 2: gRPC is often chosen there for its high performance and
- 21:21Speaker 2: strong typing, especially in polyglot environments. The point is understand
- 21:26Speaker 2: the need first, then choose the appropriate API style or technology.
- 21:30Speaker 2: Don't just default to rest for everything.
- 21:33Speaker 1: That leads to a really important question. APIs aren't static.
- 21:36Speaker 1: They need to change. How do you manage modifications and versioning?
- 21:40Speaker 2: This is critical for maintaining stability for your consumers. The
- 21:43Speaker 2: first step is understanding the difference between backward compatible changes
- 21:47Speaker 2: and breaking changes.
- 21:48Speaker 1: What's the difference?
- 21:49Speaker 2: Backward compatible changes don't break existing clients. Adding a new
- 21:53Speaker 2: optional field to a response, for example, or adding a
- 21:56Speaker 2: new value to an existing enumeration, Consumers who don't know
- 21:59Speaker 2: about the new stuff.
- 22:00Speaker 1: Just ignore it, okay, safe changes right.
- 22:02Speaker 2: Breaking changes, on the other hand, will break existing clients
- 22:05Speaker 2: if they're not updated. Renaming a required field, changing a
- 22:09Speaker 2: field's data type like from a string to a number,
- 22:12Speaker 2: removing an operation entirely, making an optional field required. These
- 22:16Speaker 2: all require consumers to.
- 22:18Speaker 1: Adapt, So how do you manage those breaking changes? That's
- 22:20Speaker 1: where versioning comes in exactly.
- 22:22Speaker 2: You need a versioning strategy. Semantic versioning like one point
- 22:26Speaker 2: oh one point one two point zero is common, where
- 22:28Speaker 2: the major version number the two point zero increments only
- 22:31Speaker 2: when you introduce braking changes. Minor increments are for backward
- 22:34Speaker 2: compatible additions. Some use deep based versioning like twenty twenty
- 22:38Speaker 2: five oh eight twenty, which can be simpler if you
- 22:41Speaker 2: release very frequently, but makes it harder to know what
- 22:43Speaker 2: change without reading talks.
- 22:45Speaker 1: And how is the version usually specified in the API call.
- 22:48Speaker 2: The most common way is path level versioning. You stick
- 22:51Speaker 2: the major version right in the URL path like V
- 22:53Speaker 2: one products or VW two products. It's simple, explicit, and
- 22:57Speaker 2: easy for routing and casing. Other methods exist head query prams,
- 23:01Speaker 2: but path is very popular.
- 23:03Speaker 1: To minimize the need for breaking changes, can you design
- 23:06Speaker 1: for extensibility from the start?
- 23:08Speaker 2: Absolutely, that's key. Make choices that leave room for future evolution.
- 23:12Speaker 2: For instance, always return chase on objects as the top
- 23:15Speaker 2: level in your response bodies. Even if you only have
- 23:17Speaker 2: one field right now, it's easy to add more fields
- 23:19Speaker 2: later without breaking things. Good tip use a raise of objects,
- 23:23Speaker 2: not just a rays of simple strings or numbers. If
- 23:25Speaker 2: you think those items might need more associated data later.
- 23:28Speaker 2: Prefer numerations like status active over simple booleans is active true.
- 23:34Speaker 2: It's easier to add more statuses later pending inactive than
- 23:38Speaker 2: to change a booleon. These small things add up to
- 23:41Speaker 2: make future changes much less painful.
- 23:43Speaker 1: Okay, we've covered the what and how of design? What
- 23:46Speaker 1: about the final layer, the design process itself, making it
- 23:49Speaker 1: reasoned and improving.
- 23:51Speaker 2: Right, This is about ensuring your design decisions aren't just
- 23:53Speaker 2: random or based on gut feeling. You need confident decision making.
- 23:57Speaker 2: That confidence comes from relying on trusted sources. Maybe it's
- 24:00Speaker 2: your own well defined internal API design guidelines. Maybe it's
- 24:04Speaker 2: established external standards like the HTTPIE speck itself, or things
- 24:07Speaker 2: like problem details, cloud events, maybe industry specific standards like
- 24:11Speaker 2: ISO twenty twenty two in.
- 24:12Speaker 1: Finance, So standing on the shoulders of giants essentially.
- 24:15Speaker 2: Kind of yeah, and importantly document significant decisions, especially when
- 24:20Speaker 2: you deviate from a standard or make a tricky trade off.
- 24:23Speaker 2: Architectural decision records ADRs are a great way to capture
- 24:26Speaker 2: the y behind a choice.
- 24:28Speaker 1: You mentioned API design guidelines. How valuable are those?
- 24:32Speaker 2: Immensely valuable. Think of them as your teams or organization's
- 24:35Speaker 2: cookbook for APIs. They provide agreed upon recipes for common patterns,
- 24:40Speaker 2: how we do CRI, how we handle searching and filtering,
- 24:43Speaker 2: standard file upload methods, how we structure errors. Having these
- 24:47Speaker 2: guidelines saves countless hours arguing about the same things over
- 24:50Speaker 2: and over again on different projects. It promotes consistency.
- 24:54Speaker 1: Can you automate the enforcement of these guidelines?
- 24:57Speaker 2: Yes, that's where automated guidelines or API line come in.
- 25:01Speaker 2: Tools like Spectral are designed for this. You can figure
- 25:03Speaker 2: the linter with your rules. Properties must be CamelCase, pagination
- 25:07Speaker 2: must use these specific parameters, air responses must follow the
- 25:10Speaker 2: problem detail structure, etc. Then the linter analyzes your open
- 25:14Speaker 2: API definition file and points out any violations.
- 25:17Speaker 1: Giving feedback directly in the design phase exactly.
- 25:20Speaker 2: It gives clear feedback, errors, warnings, info hints, helping designers
- 25:24Speaker 2: stick to the standards and catch potential issues way before
- 25:27Speaker 2: coding even starts. It's a huge boost for quality and consistency.
- 25:30Speaker 1: Finally, the open API document itself the description of the API.
- 25:34Speaker 1: Any tips for optimizing that definitely.
- 25:37Speaker 2: Make it easy to read and maintain. Use ref Jason
- 25:40Speaker 2: pointers heavily to reuse common components like schemas, parameters, standard responses.
- 25:45Speaker 2: Don't repeat yourself.
- 25:46Speaker 1: Define it once, reuse it everywhere right, and.
- 25:49Speaker 2: Enrich it with details. Use JSON schema keywords precisely specify
- 25:53Speaker 2: min length, max length, pattern regular expressions for validation enum
- 25:59Speaker 2: allowed value, use default values. The more precise the definition,
- 26:02Speaker 2: the better, and examples Examples are crucial. Include realistic examples
- 26:06Speaker 2: for request bodies, response bodies, parameters. They make the API
- 26:10Speaker 2: much easier to understand and test for consumers. Don't skimp
- 26:13Speaker 2: on examples, and as a final point on process, consider
- 26:16Speaker 2: API mocking or prototyping. Early on tools can generate a
- 26:20Speaker 2: mock server based on your opening API.
- 26:21Speaker 1: File so you can interact with it before it's built.
- 26:23Speaker 2: Yeah. Hey, let's you and potential consumers try out the design,
- 26:27Speaker 2: see if it feels right, catch awka parts, and iterate
- 26:30Speaker 2: much faster than if you wait until the code is written. Wow.
- 26:33Speaker 1: Okay, so we've really journeyed through a lot there. We've
- 26:35Speaker 1: taken you, the listener, through these layers, from figuring out
- 26:38Speaker 1: what the API needs to do, designing that interface, modeling
- 26:42Speaker 1: the beta, carefully building insecurity and efficiency, handling context, managing
- 26:47Speaker 1: change with versioning, and finally refining the whole process with
- 26:51Speaker 1: guidelines and tools.
- 26:52Speaker 2: Yeah, it really underscores the good API design isn't just
- 26:55Speaker 2: a single task. It's an ongoing craft. It's this constant
- 26:58Speaker 2: balancing act between what users need, what's technically feasible and constrained,
- 27:03Speaker 2: and how things might evolve. It's less about just banging
- 27:06Speaker 2: out code and much more about deliberately crafting these interfaces
- 27:10Speaker 2: that enable smooth, effective digital experiences for everyone involved.
- 27:14Speaker 1: So here's a final thought to leave you with as
- 27:16Speaker 1: you go about your day thinking about the systems you
- 27:19Speaker 1: build or use. What seemingly small API design choice being
- 27:22Speaker 1: made today might turn out to be a major roadblock,
- 27:25Speaker 1: or perhaps a brilliant enabler for your users and systems
- 27:28Speaker 1: down the road,