02 Nov 2020
REST (Representational State Transfer) API is a set of rules and conventions for building and interacting with web services.
Content-Type
to application/json
(many frameworks do this automatically).HTTP methods already use verbs like “GET” and “POST”. An example endpoint should look like this:
https://website.com/posts
Not like this:
https://website.com/getPosts
Do this:
https://website.com/post/1234
Not this:
https://website.com/posts/1234
Here’s a cheat sheet.
https://website.com/posts/postId/comments
Retrieving data from a database can be slow. Use filtering, sorting and pagination to only retrieve the data that you need.
https://website.com/posts?tags=cheatsheet
HTTPS should be used instead of HTTP for all requests and responses.
REST APIs should have different versions so that you don’t force your users to migrate to new versions.
The documentation should contain: → relevant endpoints → example requests → implementation in several programming languages → messages listed for different errors with their status codes