I am new to restful web development. I have tried to search for this but could not find an answer. In a restful api how do we send data to a post request? Is it sent as a query parameter. Since in a post request the data is sent using the request body using forms. How do I pass data when developing an API? is it sent as a uri parameter similar to how it happens in get request? Can you give an example post request in a rest api. For example if I want to make a post request to enter data of a student Post /student/new/?name=xys&age=28 Is this valid?
Asked
Active
Viewed 3,114 times
0
-
I'm not sure what you are asking, if you know that the data is send using the request body, then what else do you want to know? – shafeen Feb 10 '16 at 15:35
-
Possible duplicate of [Do HTTP POST methods send data as a QueryString?](http://stackoverflow.com/questions/5876809/do-http-post-methods-send-data-as-a-querystring) – Manu Feb 10 '16 at 15:38
-
@Manu this is not a duplicate, i am asking about rest web services specifically. that question is about how to make post requests. – sachin srivastava Feb 10 '16 at 16:13
1 Answers
0
Programming languages/frameworks designed to handle and make web-requests normally give you easy access to the GET or POST parameters OR give you an easy way to pass your POST parameters (all you have to do usually is mention the data as key-value pairs in an object or dictionary and the language/framework will do the work for you).
For example, this is a javascript example using jQuery:
$.post("your.api.endpoint.url", { key1:"value1", key2:"value2"});
After making this request, you should be able to open up developer tools in your browser (Ctrl+Shift+I in Chrome) and view the request headers and body and see the key value pairs at the bottom of the request body.

shafeen
- 2,431
- 18
- 23
-
hi shafeen, I know how to make a post request, i am asking in case of a rest api how is the data sent to a post request. is it using query parameters similar to get request or in the request body. Can you give an example post request to a rest api? – sachin srivastava Feb 10 '16 at 16:10
-
-
In the case of a restful "endpoint" you would make a post request just as you would make any other post request, why would it be different? – shafeen Feb 10 '16 at 16:13
-
-
In your example it would be something like : `$.post("your.api.endpoint.url/student/new/", { name:"xyz", age:28});` – shafeen Feb 10 '16 at 16:14
-
what language are you using? In javascript you just pass in an Object, in Java you use something like `ArrayList
postParameters` – shafeen Feb 10 '16 at 16:16 -
i am using python but i just have a general question. what is the rest endpoint? for example – sachin srivastava Feb 10 '16 at 16:18
-
https://dev.twitter.com/rest/reference/post/statuses/update this is a post request in twitter. where is the data specified? – sachin srivastava Feb 10 '16 at 16:18
-
-
You should post sample code on what you are attempting and that would clarify your question further. Maybe your question is "how to make a post request in YOUR language or framework", because you claim you understand what a post request is but you don't seem to understand that the endpoint here is arbitrary, you want to know how to do it in what YOU are working in. So post your code specific to your question. – shafeen Feb 10 '16 at 16:25
-
in python you can use the `requests` library for example and simply pass in a dictionary with your post data parameters (which is basically the same as the JavaScript or the Java examples) – shafeen Feb 10 '16 at 16:28
-