HTTP and Flask Basics - HTTP Responses

发布时间:2022-06-26 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了HTTP and Flask Basics - HTTP Responses脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

After the request has been received by the server and processed, the server returns an HTTP response message to the client. The response informs the client of the outcome of the requested operation.

Elements:

  • Status Code & Status Message
  • HTTP Version
  • Headers: similar to the request headers, provides information about the response and resource representation. Some common headers include:
    • Date
    • Content-Type: the media type of the body of the request
  • Body: optional data containing the requested resource.

HTTP and Flask Basics - HTTP Responses


Status Codes As an API developer, it’s important to send the correct status code. As a developer using an API, the status codes - particularly the error codes - are important for understanding what caused and error and how to proceed.

Codes fall into five categories

  • 1XX: Informational
  • 2XX: Successful response
  • 3XX: Redirection (Something happen and there was a redirection and the back end)
  • 4XX: Client Error
  • 5XX: Server Error (The client sent a request that was fine but something happened in the back end such that the server couldn’t successfully process and needs to let the user know that.)

Common Codes

  • 100: Continue (You would see for that options request which basically says, “I got the options you have permission to process, continue sending your request.”)
  • 200: OK (For the GET request)
  • 201: Created (That is going to go with a POST request.)
  • 304: Not Modified (If a PUT or PATCH request was unsuccessful)
  • 400: Bad Request (This is one of those client errors, it means something about that request format was wrong and the server could not handle it.)
  • 401: Unauthorized (The request was formatted fine but you don’t have access to what you wanted to do or to that resource either the operation or the resource or both)
  • 404: Not Found (Whatever resource you were requesting doesn’t actually exist in the back end.)
  • 500: Internal Server Error (This one is broad category of something happened in the server while attempting to process a valid request from the client and it was not able to be completed.)

脚本宝典总结

以上是脚本宝典为你收集整理的HTTP and Flask Basics - HTTP Responses全部内容,希望文章能够帮你解决HTTP and Flask Basics - HTTP Responses所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: