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.

请添加图片描述


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.)
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码

)">
< <上一篇
下一篇>>