HTTP status code for “no data available” from an external datasource

后端 未结 5 1668
梦谈多话
梦谈多话 2020-12-29 01:20

Scenario:

A POST request is sent to process an order that will result in data retrieval from an external datasource.

There are

5条回答
  •  灰色年华
    2020-12-29 01:47

    1. The datasource returned data for the request
    200: OK/201: CREATED
    Because everything is working as expected
    
    1. No data was available for the request (this is viewed as an error)
    400: BAD REQUEST
    The request was invalid or cannot be otherwise served. An accompanying error message will explain further inside the body.like:
    HTTP 400
    {
    response: null,
    code: "USER_101", //should be used customized error codes here
    error: "User details not found"
    }
    
    1. The datasource couldn't be accessed (may be down for maintenance)
    404: Resource/URI NOT FOUND
    The URI requested or resource is invalid
    Like: https://www.lipsum.com/list-page
    **/list-page** is not defined/found
    

    Find here most frequently used status codes:

    200 – OK
    Everything is working, The resource has been fetched and is transmitted in the message body.
    
    201 – CREATED
    A new resource has been created
    
    204 – NO CONTENT
    The resource was successfully deleted, no response body
    
    304 – NOT MODIFIED
    This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.
    
    400 – BAD REQUEST
    The request was invalid or cannot be served. The exact error should be explained in the error payload.
    
    401 – UNAUTHORIZED
    The request requires user authentication.
    
    403 – FORBIDDEN
    The server understood the request but is refusing it or the access is not allowed.
    
    404 – NOT FOUND
    There is no resource behind the URI.
    
    500 – INTERNAL SERVER ERROR API
    If an error occurs in the global catch blog, the stack trace should be logged and not returned as a response.
    

提交回复
热议问题