JSON data to web service- how do define expected JSON data

前端 未结 2 645
一生所求
一生所求 2021-01-28 13:46

I am building a RESTful web service in PHP that accepts JSON as its payload . Now, my question is, how exactly do I describe to the user the format that the JSON request comes i

相关标签:
2条回答
  • 2021-01-28 13:54

    Adhering to the guidelines of REST, the input you get from the users of the API should either be part of the URL (for a GET request; doesn't update data, i.e. http://example.com/api/doc/1243), or should be a POST variable (sent in the body of the HTTP request, to the same URL).

    So for documentation, all you should need to do is indicate the endpoint URL (http://example.com/api/doc/1243), the fact they need to use POST, and what the variables are (i.e. title, body, author, etc.). Then users will form the proper HTTP request however they want, and on your server end, because you're using PHP, you'll pull their variables from the $_POST array (i.e. $_POST['title'], $_POST['body'], etc.)

    0 讨论(0)
  • 2021-01-28 14:14

    Dropbox is a good example of restful api that uses JSON as payload.

    You will also get a good idea about how you can document your API as well.

    0 讨论(0)
提交回复
热议问题