How to (and how not to) design REST APIs
github.com
How to (and how not to) design REST APIs
1–10 of 153 posts
Re: How to (and how not to) design REST APIs
#2Re: How to (and how not to) design REST APIs
#3Re: How to (and how not to) design REST APIs
#4Half of the points are complete bs. URLs don’t matter in REST. What matters are link relations.
Re: How to (and how not to) design REST APIs
#5But I feel 410 instead of 404 is pretty controversial:
> There are many layers of software that can return 404 to a request
Anything in your stack can return any HTTP error code - I don't see why 404 is special.
> When calling (say) GET /things/{thing_id} for a thing that doesn't exist, the response should indicate that 1) the server understood your request, and 2) the thing wasn't found. Unfortunately, a 404 response does not guarantee #1.
The server is free to return other codes for other classes of problems. The server could return 400 for a bad request, and leave 404 for "thing wasn't found", indicating it understood the request but it wasn't found.
Also surprised not to see RFC 7807 / RFC 9457 (Problem Details) not mentioned in the "structured error format" section.
Re: How to (and how not to) design REST APIs
#6 # GOOD
GET /products # get all the products
GET /products/{product_id} # get one product
# BAD
GET /product/{product_id}
But then in Rule 2: GET /shop/{shop_id}/listings # normal, expected
Shouldn't that be "/shops/{shop_id}/listings"? Or is it plural only if you can actually GET the path (i.e. there's no GET for just "/shop") and otherwise it should be singular?Re: How to (and how not to) design REST APIs
#7Edit: Bring on the downvotes. I will die on this hill.
Re: How to (and how not to) design REST APIs
#8It's worth it for your public API, but it's such a huge time sink for internal APIs.
Re: How to (and how not to) design REST APIs
#9Avoid plural nouns in English API endpoints because English is full of irregular plurals. For example:
goose -> geese child -> children index -> indices vertex -> vertexes analysis -> analyses
This makes English plurals unpredictable especially for for non-native speakers and hurts API consistency and discoverability.
Also consider that for a CRUD interface you may need the singular form anyway (POST api/student/create), and adding the plural means doubling the API route namespace.
It's cleaner and simpler to stick with singular nouns.
Re: How to (and how not to) design REST APIs
#10Some good points - particularly about not returning arrays (I've made that mistake!) But I feel 410 instead of 404 is pretty controversial: > There are many layers of software that can return 404 to a request Anything in your stack can return any HTTP error code - I don't see why 404 is special. > When calling (say) GET /things/{thing_id} for a thing that doesn't exist, the response should indicate that 1) the server…
> You could use 404 but return a custom error body and demand that clients check for a correct error body. This is asking for trouble from lazy client programmers. It might or might not be "your fault" when clients see eventually inconsistent data, but the support calls they send you will be real.
Make sure that your 404 responses were always documented, then tell them to RTFM.