Found a contradiction that I don't understand. From rule 1: # 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 sing…
How to (and how not to) design REST APIs
11–20 of 153 posts
Re: How to (and how not to) design REST APIs
#12Half of the points are complete bs. URLs don’t matter in REST. What matters are link relations.
Care to elaborate briefly on why they do?
Re: How to (and how not to) design REST APIs
#13Regarding #8 - just do not use http status codes for application errors. They are for routers, caches and proxies. Your application should pretty much only return 200 even on errors. Edit: Bring on the downvotes. I will die on this hill.
Re: How to (and how not to) design REST APIs
#14Found a contradiction that I don't understand. From rule 1: # 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 sing…
Re: How to (and how not to) design REST APIs
#15Rule #1 is terrible advice. Avoid 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 a…
Why? What's wrong with api/students/create?
> Avoid plural nouns in English API endpoints because English is full of irregular plurals.
I don't buy this. I mean, yes, it's true, but how often do people really need to write these endpoints after initially writing the client code?
Re: How to (and how not to) design REST APIs
#16Havn't we talked about building REST APIs enough yet?
Re: How to (and how not to) design REST APIs
#17* If you’re going to forbid people changing a parameter with a PUT or PATCH request, then the schema for these shouldn’t list them as parameters. This seems to creep in to APIs constantly as people are lazy and will use the same serializer method as for POST with an additional check somewhere in the code that changes the response. Just don’t do it!
* Don’t change the response format based on query parameters. It makes it hard for typed languages to use the API because the client has to handle all of the weird response types you’ve got. Inevitably you end up with more and more getting added and it any client becomes crazily complicated. 99% of the time it’s not worth the bandwidth saving - and if there’s lots of useless information that clients don’t want, it’s worth thinking about whether the API design is right in the first place.
* Stick to one mechanism for doing things. Pagination and sorting behaviour should be the same for all endpoints. The end user doesn’t care that you’re a hip microservices company where teams don’t talk to each other - if the APIs behave weirdly and inconsistently between themselves, it will be hard to use.
Re: How to (and how not to) design REST APIs
#18Re: How to (and how not to) design REST APIs
#19Rule #1 is terrible advice. Avoid 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 a…
GET /students
So you can't escape the problem unless you want `GET /child` to fetch multiple children.Also, you should avoid verbs in URLs (IMHO, of course). You're adding to the students collection, so post to students:
# BAD
POST /student/create
# GOOD
POST /studentsRe: How to (and how not to) design REST APIs
#20Rule #1 is terrible advice. Avoid 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 a…
GET api/student
POST api/student/create
DELETE api/student
it should be
POST api/students
GET api/students
DELETE api/students