Skip to content

Instantly share code, notes, and snippets.

@kanelv
Last active March 27, 2024 05:10
Show Gist options
  • Save kanelv/10b94ccbe25a6a99101bc3590c7a3233 to your computer and use it in GitHub Desktop.
Save kanelv/10b94ccbe25a6a99101bc3590c7a3233 to your computer and use it in GitHub Desktop.
REST API Naming Guidelines
# REST API Naming Guidelines
API routes should typically be named using nouns rather than verbs.
This aligns with the principle of using HTTP methods (verbs) like GET, POST, PUT, DELETE, etc., to perform actions on the resources represented by the nouns.
## Some guidelines for naming API routes
1. Use nouns: Name your API routes after the resources they represent. For example, if you have a resource representing users, the route could be /users.
2. Use plural nouns for collections: When dealing with collections of resources, it's a convention to use plural nouns. For example, /users for a collection of users, /posts for a collection of posts, etc.
3. Avoid verbs in route names: Instead of incorporating verbs into your route names, use HTTP methods like GET, POST, PUT, DELETE to indicate actions to be performed on resources. For example, to retrieve a specific user, you might use a route like /users/{userId} with a GET request.
4. Keep routes simple and intuitive: Routes should be easy to understand and follow. They should reflect the structure and hierarchy of your resources.
## A brief example illustrating these guidelines:
GET /users: Retrieve a list of users.
POST /users: Create a new user.
GET /users/{userId}: Retrieve a specific user.
PUT /users/{userId}: Update a specific user.
DELETE /users/{userId}: Delete a specific user.
## Credit
ChatGPT 3.5
2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment