Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API requires POST arguments in a query string?

I'm playing with the Twitter API and noticed something funny- For updates, they require POST methods but expect the arguments in the query string. (See for example, the status/update call in their developer console here.)

Obviously this is technically possible, but why would anyone do it like that? Don't POST arguments belong in the body?

like image 998
Yarin Avatar asked May 02 '12 01:05

Yarin


People also ask

What is query string in API?

A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters.

Can a post request have a query string?

A POST request can include a query string, however normally it doesn't - a standard HTML form with a POST action will not normally include a query string for example.

What is a query parameter in API?

What are API Query Parameters? API Query parameters can be defined as the optional key-value pairs that appear after the question mark in the URL. Basically, they are extensions of the URL that are utilized to help determine specific content or action based on the data being delivered.


2 Answers

Either option is just as valid. My favourite example for using parameters in the URL for a POST is an application that sets waypoints on a map. e.g.

     POST /map/route/45/waypoints?lat=35&long=74

In this case, the parameters make more sense in the URI as identifiers of a location, than just parameters being passed in the body to generic resource.

like image 187
Darrel Miller Avatar answered Sep 28 '22 01:09

Darrel Miller


In REST architecture, GET and POST are just the verbs, which tells either to retrieve or create/update the resource. URI defines the identification of resource.

Example:

POST /student?name=Tom&age=12 >> It will create a new student with name Tom and age 12.
POST /student/10?name=Tom&age=12 >> It will update student with id 20 with name Tom and age 12.

There is no rule that the data should be binded to body payload or URI. This is different from WEB 1.0 concepts where HTML form data is sent in POST.

like image 41
shashankaholic Avatar answered Sep 28 '22 01:09

shashankaholic