python - response about restful api
伊谢尔伦
伊谢尔伦 2017-06-28 09:25:24
0
5
931

I just started to get in touch with the web, and I don’t know a lot of common sense. Want to ask.
An API only has a post method. If someone accesses it through other methods, what kind of information needs to be returned.
besides. . A response must contain certain information. Can you give me a specific json example? .

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(5)
三叔

Give you a kind-hearted person’s gitup link. There are many restful API documents in it, which will benefit you a lot.

restful api information gitup

我想大声告诉你

If you only need the post method
you need to return405 Method Not AllowedError
As for the response body, you can customize it
I usually

{
  "errcode": 405,
  "errmsg": "Method Not Allowed"
}
代言

The restful protocol API has many request methods, and POST can be used as a general method to change data. There are two types of response. One is to directly return the information in the response header via HTTP. This is usually set in the header information when setting the return information. And if you want to use this as a business distinction, you can set custom fields according to the answer above. You can set them at will, and it will be OK if they comply with the team's development specifications.

迷茫

Response header: code msg data. Generally speaking, this is all that is needed for projects. The api does not only have the post method

学霸

Are you saying that the answer does not meet the requirements of the question? It's noisy.

---------------Original answer------------------------

If you want "an api only has post method", then other requests should return 4xxerror code.

The fixed information of the response needs to be agreed upon by the front and backends themselves. Usually at least three fields are required to represent the request status, data, and prompt information. In actual business, more can be added, for example:

{
    status:'',
    data:[],
    msg:'',
    count:99
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template