www
www copied to clipboard
RESTful API Design: 13 Best Practices to Make Your Users Happy
RESTful API Design: 13 Best Practices to Make Your Users Happy
First step to the RESTful way: make sure errors don't come back as 200 OK.
Great article! Thanks.
Straight to the point 👍👍👍
Nice article! what about sorting? thanks.
@syeikhanugrah api/articles?sort=+author,-publishedDay -publishedDay means Descending +author means ascending , + can be omitted. When looking into your question seen an example to use * to prefix calculated fields. https://jsonapi.org/format/#fetching-sorting
Thank you for your effort, the article very clear and have great examples for easy understanding.
👍👍👍, learned this article.
NIce and easy explanation
Nice one, very informative and well structured!!
This is the best article I've seen REST API design guide. So simple and straightforward.
I agree with not to use verb in URI. But what is the proper way to deal with the case below?
A user sign up a new account and submit related document for identity verification.
Endpoint for admin: GET: /users ---> get all users POST: /users ---> create new user GET: /users/12345 ---> get user info PATCH: /users/12345 ---> edit user info (name, contact, address...)
We may have more than one action on a resource. Example:
- Admin help to reset password for user "12345"
- Admin change the isVerified = true after review their submitted document.
My ideas as below but they seem like not proper.
- PATCH: /users/12345/reset-password
- PATCH: /users/12345/verify-identity
Any thought?
@OKT92
Yes, these are not proper.
- PATCH: /users/12345/reset-password
- PATCH: /users/12345/verify-identity
I suggest an example.
Edit user's partial information example
Request: [PATH] /users/12345
- user authentication logic is executed
- accept like below request body
{
"new_password": "~~~~"
"new_address": "~~~"
}
- Reflect update
Response
204 No Content
There's no response body
Conclusion
Recommend that use API URI without verb, nested path (You can specify entity id, in this example 12345
) and also use response 204 No Content
when PATCH
request is done successfully
Refer this document