I'd like to leave a few tips that I think are adamant in writing good APIs. I've come across all of these mistakes, and they are a pain to deal with. Some more than others, but all decrease the enjoyability of working with them.
camelCase, PascalCase, or snake_case, just use the same kind everywhere;reference-data and another public_posts;user, other endpoints that contain a user should not have them under the key person;nil, null, or empty object (at the worst case). For example, do not return an empty array where you'd usually find a dictionary;REST methods, for example DELETE /users/1, don't have other endpoints use a path component for the same functionality, for example GET /posts/1/delete;query and pageSize, don't have other endpoints expect q and ps;HTTP code, for all endpoints. For example, if a resource can not be found, don't return 400 for one endpoint and 404 for another.REST APIs, use its methods instead of path components:
GET to get a resource;POST to create, instead of GET /users/create;PUT to update, instead of GET /users/1/update;DELETE to delete, instead of GET /users/1/delete;/v1/users/1. Even if you're absolutely sure you won't need it, it's still good practice. Never say never.{
"id": 1234,
"name": "Roland Leth"
}
// vs
{
"user": {
"id": 1234,
"name": "Roland Leth"
},
// Room for new data here
}