HTTP 拾遗
http

HTTP 拾遗

HTTP API endpoints endpoint(端点) 是指一个网络服务或者接口所提供的唯一的访问地址。在 HTTP 协议中,每个 URL(Uniform Resource Locator)...

更新于 2024-01-05
1217

HTTP API endpoints

endpoint(端点) 是指一个网络服务或者接口所提供的唯一的访问地址。在 HTTP 协议中,每个 URL(Uniform Resource Locator)可以被视为一个 endpoint。正确地定义API 的 endpoint 对于构建高质量的 Web 服务至关重要。

在 API 设计中,HTTP endpoint 的多个单词通常使用下划线进行连接,称为下划线命名法或蛇形命名法(snake case),例如 "/user_profiles"、"/product_reviews" 等等。用中划线连接的方法(短横线命名法或减号命名法,kebab case),由于在 HTTP 协议中连字符有特殊含义,可能会引起歧义和错误,一般不建议使用。如果真的需要使用中划线,则必须要注意对应的语言框架或库是否支持该方式,并且正确处理连字符带来的问题。

redirect

a redirect from /users to /people: if you make a POST request to /users to create a new user, and are conforming to a 302 temporary redirect, the request method will be changed from a POST to a GET request.

  • 302 - Temporary redirect, will change the request method from POST to GET
  • 307 - Temporary redirect, will preserve the request method as POST

The 303 See Other status code is typically returned as the result of a POST, PUT, or DELETE HTTP request. Essentially, it means that the result of the HTTP request can be found at a different URL. To fetch the new resource, the client must use a GET HTTP request with the specified Location.

参考: https://nextjs.org/docs/app/api-reference/functions/redirect#why-does-redirect-use-307-and-308