Product knowledge · Beginner · Request anatomy
Một URL không phải một route pattern.
Tách từng thành phần của request để biết Core parse và giữ wire facts ở đâu, còn application decode, validate và gắn business meaning ở đâu.
Product knowledge · Beginner · Request anatomy
Tách từng thành phần của request để biết Core parse và giữ wire facts ở đâu, còn application decode, validate và gắn business meaning ở đâu.
01 · One concrete request
GET http://127.0.0.1:8080/orders/A%2FB?tag=one&flag&tag=&tag=two#receipt
└── scheme + authority ──┘ └ path ┘ └──────── query ────────┘ └ browser fragment
route declaration: GET /orders/{id}
wire request target: /orders/A%2FB?tag=one&flag&tag=&tag=two
captured id: A%2FBScheme, authority, path và query dùng ở browser/curl/client. Fragment chỉ ở browser, không gửi tới server.
Bind address + port là startup configuration, không nằm trong route declaration.
Route và request đều có method; comparison case-sensitive theo contract.
Core parse path/query, áp dụng bounds và chiếu facts qua connector.
02 · Route declaration
| Pattern | Nghĩa |
|---|---|
/ | Exact root. |
/health | Exact static path. |
/orders/{id} | Một nonempty whole-segment capture. |
/orders/{orderId}/items/{itemId} | Hai capture theo path order. |
/orders/{id}/ | Trailing slash là một phần của pattern. |
Không khai báo full URL, query template, Express :id, regex, optional segment hay catch-all *. Static segment thắng capture ở vị trí khác nhau đầu tiên; ambiguous same-structure patterns bị reject, không giải bằng registration order.
03 · Path and captures
/items/a%2Fba%2Fb; encoded slash vẫn ở trong một segment vì boundary được xác định trước decode./users vs /users/04 · Ordered query entries
| Wire input | Meaning |
|---|---|
không có flag | Key absent. |
?flag | Key present, value absent. |
?flag= | Key present, empty value. |
?tag=one&tag=two | Hai ordered entries; không overwrite thành một map value. |
?q=a+b | Encoded value giữ +; không tự form-decode thành space. |
?q=a%26b | Một value chứa encoded &. |
Query không chọn route khác. Handler sở hữu business behavior; khi dựng query, dùng URL encoder của client thay vì nối untrusted text.
05 · Headers
Content-Type và content-type lookup cùng tên theo HTTP rule.
Dùng ordered/all-values view khi duplicates có nghĩa; đừng collapse nếu connector giữ chúng.
Core kiểm tra count/bytes trước application use. Limit failure có thể xảy ra trước handler.
Không reflect arbitrary inbound headers, cookies, authorization hoặc credential vào response/log.
06 · Body and trailers
07 · Building outbound intent
logical target: billing.api
connection endpoint: 10.0.2.15:8443
HTTP authority / TLS identity: billing.internal
method: POST
origin-form target: /charges/customer-7?notify=true
deadline: finite
wrong: /charges/{customerId}
wrong: https://billing.internal/charges/... in a path/query-only fieldConnect destination, HTTP authority và TLS peer identity là ba setting riêng. Successful submit chỉ nghĩa admitted; đọc matching terminal để phân biệt HTTP 4xx/5xx response với cancellation, deadline hoặc transport failure. Retry/idempotency vẫn thuộc application.
08 · Request checklist