Basic REST callouts
As we discussed in the previous chapter in our overview of RESTful APIs, a REST call is made of an HTTP method (GET
, POST
, PUT
, PATCH
, or DELETE
) and a URL. Data may be provided to the endpoint via the URL in the parameters or through the body. Additionally, an HTTP request also contains a header that will include information for the receiving system, such as authentication details and encoding information (that is, whether the data being transferred is in JSON, XML, or other format).
When making a REST callout from Apex, we must be able to provide all these pieces of information to create a correctly formatted request for the external system to process. Throughout the following sample code, I will be using the Postman Echo endpoints (you can find more information at https://postman-echo.com). Postman is an extremely popular API development and testing tool, and the Echo API provided by Postman simply returns all the data provided to the endpoint in the response...