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.
Know first
EndpointAPI Endpoint
GET/api/posts→ List processing
POST/api/posts→ Create processing
GET/api/posts/:id→ Details processing
Method and path together determine which code to enter

When to use it

  • Read a collection or record
    The method describes the action; the path identifies the resource.
    Read userGET /usersCreate userPOST /users
  • Create, update, or delete data
    Put the three parameter types in different places
    Path/users/42Query?tab=ordersRequest body{ "name": "Jordan" }
  • Receive a form or webhook
    Every endpoint should define four things
    InputemailSuccess201Failed400 / 409PermissionSign-in required
  • Expose one clear backend capability
    Test the endpoint by itself first
    curl -X POST /api/orders201 Created{ "orderId": "o_42" }

When NOT to use it

  • Use one endpoint for many unrelated operations
    One endpoint handles everything
    POST /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 method
    Method and action conflict
    DeleteGET /delete/42ReadPOST /getUser
  • Return private records without authorization
    Design only the success path
    200 success500 failureNo recovery guidance
    Missing parameters and service failures also need clear responses.
  • Hide every failure behind the same generic response
    Sensitive information appears in the URL
    GET /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 deletion
Confirm first, then request DELETE /api/tasks/t_42
Further reading