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? .
三叔2017-06-28 09:27:24
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
我想大声告诉你2017-06-28 09:27:24
If you only need the post method
you need to return405 Method Not Allowed
Error
As for the response body, you can customize it
I usually
{
"errcode": 405,
"errmsg": "Method Not Allowed"
}
代言2017-06-28 09:27:24
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.
迷茫2017-06-28 09:27:24
Response header: code msg data. Generally speaking, this is all that is needed for projects. The api does not only have the post method
欧阳克2017-06-28 09:27:24
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 4xx
error 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
}