HTTP notes
Status code
204
- Status 204 代表的是「請求成功,但沒有 BODY」, 這個比較常用在 DELETE 操作
304 Not Modified
- There is no need to retransmit the requested resources.
This happens when:
- the request method is a safe method, such as
GET
orHEAD
- when the request is conditional and uses an
If-None-Match
or anIf-Modified-Since
header.
{
"header": {
"If-None-Match": <e-tag>
}
}
HTTP Header
X-HTTP-Method-Override
For some HTTP clients can only work with simple GET and POST requests. Use X-HTTP-Method-Override
with a string value to contain PUT
, PATCH
, DELETE
X-Total-Count
- A count of the total number of Pagination count
E-tag
- The server gives client resources associated with E-tag
Next time, the client sends the same request with given E-tag, the server will use that E-tag to tell if it changes or not
header: If-None-Match
=> if resource is not changed, status 304 not Modified => response quickly
Pros
- Fast response
- Less bandwidth
- Control consistency and concurrency
Cons
- Two servers behind load balancer may generate two E-tags (But it is configurable!)
- E-tag can be used to track users (e-tag is harder deleted than cookie)
References
- HTTP Caching with E-Tags — (Explained by Example) — YouTube (2018)
- 304 Not Modified HTTP Status (Explained with Code Example and Pros & Cons) — YouTube (2020)
- https://chengr4.medium.com/restful-api-notes-3b3185391718
- https://chengr4.medium.com/%E8%A8%88%E7%AE%97%E6%A9%9F%E7%B6%B2%E8%B7%AF%E5%92%8C%E7%B6%B2%E9%9A%9B%E7%B6%B2%E8%B7%AF-application-layer-7f77e3cdcdd1