3 ms·
> 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 appr
by 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.