What are the pros and cons of different ways of passing HTTP POST parameters to a REST API?
-
Pros and cons of: PassingĀ in individual parameters as HTTP form parameters Passing in JSON as the request body Passing in JSON as a form parameters
-
Answer:
I think the best choice is JSON as request body. It is better than form-encoded parameters mainly for two reasons: it has the same format that you receive when performing a GET operation it can better define data structures (embedded elements) Moreover you can use a custom Media Type (via Content Type header), one of the core elements of REST definition (see representation metadata in Fielding's dissertation).
Michele Zonca at Quora Visit the source
Other answers
TL;DR - JSON as HTTP Post Body is the best way. Three options in the question demonstrating three ways to encode data. We can encode (flat) data as form parameters (1), we can encode data as JSON (2) and then we can do both (3). Obviously double-encoding data makes no sense, so 'Passing in JSON as form parameters' is out. Comparing (1) and (2) I would prefer simpler solution and it is 'passing in JSON as the request body'. It is not only simpler, but also have better support for nested data. Additionally to that I would like to add that it is important to realize that that POST is not idempotent (see http://en.wikipedia.org/wiki/Idempotence). One should see POST as a HTTP Verb addresses do a particular resource, and in case of failure re-POST is not expected or better to say failures should be handled with extreme care by POST requests.
Renat Zubairov
Related Q & A:
- What are the pros and cons of having a pet rabbit?Best solution by Yahoo! Answers
- What are the pros and cons of a pharmacist?Best solution by Yahoo! Answers
- What are the pros and cons of buying a house using an FHA loan?Best solution by Personal Finance and Money
- What are the pros and cons of a career in marketing?Best solution by Quora
- What are the pros and cons of being a Corporate or International Lawyer?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.