I'm unsure as to when I would fill in the body of an Http POST request. I've read that the body is where you pass parameters such as "para1=value1¶2=value2" to the POST request, but why would I need to do this? If I'm simply trying to post some data to a specified location in my servers, why would I pass in extra parameters in the body?
- You would use the body when passing data that has relationships more complicated than what can be expressed in the URL.SiKing– SiKing2016-06-13 21:32:36 +00:00Commented Jun 13, 2016 at 21:32
- so the body isn't necessary for the request to be valid? If I'm passing data thats relatively simple, I can leave it blank?David Tamrazov– David Tamrazov2016-06-13 21:37:37 +00:00Commented Jun 13, 2016 at 21:37
- Yes. Perhaps have a read through this: en.wikipedia.org/wiki/…SiKing– SiKing2016-06-15 15:04:30 +00:00Commented Jun 15, 2016 at 15:04
- All righty will do, thanks a bunch @SiKing!David Tamrazov– David Tamrazov2016-06-15 17:26:09 +00:00Commented Jun 15, 2016 at 17:26
- Short on time yesterday. Composed a little better(?) answer today.SiKing– SiKing2016-06-16 15:22:29 +00:00Commented Jun 16, 2016 at 15:22
1 Answer
In order to be RESTfull, all parameters - passed either in the URL or as body - are optional. REST does not require a body be passed for a POST operation.
The choice between using URL parameters or body parameters is an architecture decision. For complicated objects, you will probably not be able to express them using only URL parameters. Note that a combination of both URL and body parameters is also valid.
The only thing you should adhere to is that GET, PUT and DELETE are idempotent, whereas POST is not. More information is available on Wikipedia and other sources on the net.