3 ms·
Some questions that aren't answered in the article: How do you structure batch operations like creating multiple things? Is the current answer to make N queri
by jayd16 7y ago
Some questions that aren't answered in the article:
How do you structure batch operations like creating multiple things? Is the current answer to make N queries and hope you're using http/2?
Whats the best practice for media types in a json api? Should every object type have a specific media type or maybe just a normal and error wrapper type? Seems like most of the big tech apis don't actually get more specific than 'application/json'.
- wwweston 7y ago> Should every object type have a specific media type Probably not. Consider that a given object in a system might have a json representation, an xml representation, an html representation, etc. Media types are less about the in-system representation or type for a given entity, and more about how the entity is rendered. Many different in-system entities might be represented by the same media type, a single in-system entity might be rendered as several media types. (In practice, yeah, application/json will cover you, though application/vnd.api.vN+json gives you some room to maneuver negotiate version/app specifics with various clients using Accepts headers.)
- veesahni 7y ago> How do you structure batch operations like creating multiple things? Is the current answer to make N queries and hope you're using http/2? OP here. Two approaches: 1. Have a special endpoint (POST /batch) where you send an array or requests [ {method: "", path: "", body: ""} ] and get an array of responses 2. Yes, assume HTTP/2 Based on conversations with teams who've based their API designs on this post, I've previously recommended #1. But it has it's flaws - a request that's dependent on response from another can't be part of the same batch. Today, I'd say it makes sense to make sure you implement your API with HTTP/2 and reduce per-hit rate limit "costs" for clients connecting with HTTP/2. This way, you're encouraging HTTP/2 adopting for heavy API users. Note, if you need to batch only on GET, then something like GraphQL is also interesting.
- jayd16 7y ago>Have a special endpoint (POST /batch) This is what always seems hacky to me. Why don't we start with batch handling. Why shouldn't every (POST /resources) accept an array of new resources? We've already resigned to using plural everywhere. HTTP/2 would be nice, but as a dev that has to serve Unity client, we can't even design APIs that require PATCH.