On a standard POST call to a REST endpoint. The receiving endpoint expects a payload on the body of the POST. The service then parses the content of the body.
For example on the following Salesforce endpoint
I created a POST request and sent on the body the following JSON:
With Apex REST here are two ways you can create your REST POST service method
- Create the method and pass the JSON as a string, then use the different Salesforce JSON parser methods to deserialize the JSON string. – read my post on Parsing JSON to know more
- Create the method and supply the parameters for the function. Salesforce Apex REST will attempt to deserialize the payload data into those parameters.
Note: With this method passing the following XML payload will also work.
Consider the following when choosing which method to implement
- If payload is easy and won’t change – method with parameters.
- Do you have accept both JSON and XML payload – method parameters
- For complex payload structure – method with User-defined type payload or the json String payload