What are headers
Headers (or more specifically HTTP headers), are used to give information about the request and basically to give instructions to the API of how to handle the request.
Headers are sent as key/value pairs that are separated by a colon (:) such as this: Content-Type: application/json
This particular header will tell your API what type of content the request contains. Within your API’s documentation, it should tell you which headers (if any) you need to provide.
How to add headers
Adding headers is possible by simply adding the parameters as name/value pairs into the Headers field within the endpoint, as shown below.
The plugin automatically adds the colon that is required to seperate the key:value, so adding these parameters as shown above will create and send the following headers:
Content-Type: application/json
apiKey: 12345678
When to use headers
You should use headers when your API documentation says so!
Using headers is a very popular method for authentication as well as for many other different uses. But again, refer to your API’s documentation to know if you need to use the headers.
Going further
Sometimes you may need to use dynamic variables in the headers.
This means that you may need to, for example send a user_id value in the headers depending on which user is logged in. This is possible when using the Pro Plugin, which adds a new attribute to the shortcode and template tag.
Here is a guide for using dynamic variables in the headers.