I previously wrote about adding custom headers to Alamofire 3 calls. Let’s figure out how to handle custom headers in Swift 3 and Alamofire 4.
When dealing with custom headers in Alamofire requests you might need to include a header for all of your API calls or just for a single call. We’ll show how to handle both of those scenarios and the four different ways that headers can be included in Alamofire calls.
The custom headers we set up previously were an API key and JSON accept header for the Mashape API:
- X-Mashape-Key: MY_API_KEY
- Accept: application/json