Reputation: 106
It may be REST or SOAP .... why should we use XML or JSON for request body for a web service why dont we use simple string like parameter=value&also=another in request body ( MIME TYPE: x-www-form-urlencoded )?
Actually it works on normal html form submission with php method ( MIME TYPE: x-www-form-urlencoded ) and it is default...
Doesnt it work on Web Services like REST ? If it works... on what reason XML or JSON is used instead? If reason regarding SOAP is that it uses HTTP+XML based protocol... lets skip it and consider only REST ......
Upvotes: 0
Views: 2083
Reputation: 864
As per the HTTP spec, you can send any content type you like in an HTTP response as long as you provide the appropriate Content-type
header.
The main benefit of JSON and XML over a plain query string is that they support hierarchies and complex data structures, e.g.:
{"cars":[{"manufacturer":"Ford"}, {"manufacturer":"GM"}]}
or
<cars>
<car>
<manufacturer>Ford</manufacturer>
</car>
<car>
<manufacturer>GM</manufacturer>
</car>
</cars>
These kinds of structures are usually very useful for webservices, and can't really be achieved with a plain query string.
Upvotes: 2