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.
EndpointAPI Endpoint
When to use it
- Read a collection or recordThe method describes the action; the path identifies the resource.Read userGET /usersCreate userPOST /users
- Create, update, or delete dataPut the three parameter types in different placesPath/users/42Query?tab=ordersRequest body{ "name": "Jordan" }
- Receive a form or webhookEvery endpoint should define four thingsInputemailSuccess201Failed400 / 409PermissionSign-in required
- Expose one clear backend capabilityTest the endpoint by itself firstcurl -X POST /api/orders201 Created{ "orderId": "o_42" }
When NOT to use it
- Use one endpoint for many unrelated operationsOne endpoint handles everythingPOST /api/doEverything{ "action": "maybe-save-or-delete" }The endpoint name does not clearly express whether it reads, updates, or deletes.
- Change data through a read-only methodMethod and action conflictDeleteGET /delete/42ReadPOST /getUser
- Return private records without authorizationDesign only the success path200 success→500 failure→No recovery guidanceMissing parameters and service failures also need clear responses.
- Hide every failure behind the same generic responseSensitive information appears in the URLGET /report?api_key=sk-live-••••Browser history · access logs · shared screenshots
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
