Route & Endpoint
You might say
When people visit different URLs, how do I send each one to the right code?
Match a request path and method to the code that handles itA backend route, or endpoint, defines where a request goes and which methods it accepts. For example, GET /products may read products while POST /products creates one. Validate input, check access, return meaningful status codes, and keep unrelated operations separate.
When to use it
- Read a collection or record
- Create, update, or delete data
- Receive a form or webhook
- Expose one clear backend capability
When NOT to use it
- Use one endpoint for many unrelated operations
- Change data through a read-only method
- Return private records without authorization
- Hide every failure behind the same generic response
Anatomy
GET/api/posts?page=2
GET reads, POST creates, PATCH updates, and DELETE removes.
The resource address, usually a consistent noun.
Used for filtering, search, sort, and pagination—not secrets.
Typical use cases
List products
Post listGET /api/posts
Request parameters?page=2&tag=design
→
Responses200 · 20 articles
Create account
Submit loginPOST /api/login
Login
The request body carries account information, and the session is established after success
Update profile
User detailsGET /api/users/:id
Path parameterid = u_23NameAlex ChenRoleeditor
Receive webhook
Delete tasksDELETE /api/tasks/:id
TaskOrganize homepage copyAfter deletionProcess according to product strategy
Confirm deletionConfirm first, then request DELETE /api/tasks/t_42
Further reading