Search code examples
iosrequestrestkit

RestKit add custom header for all requests?


I am using RestKit for my iOS app.
I would like to add a custom header for all requests.

Is it possible to add a single header in one place and have all my RestKit requests use it? If so, where do I add the code?
If not - do I have to add a header for every single request I make?


Solution

  • You can set the header on the client that the RKObjectManager creates, after initializing the RKObjectManager:

    RKObjectManager *manager = [RKObjectManager managerWithBaseURL:@"https://mycompany.example.com/rest/"];
    
    [[manager HTTPClient] setDefaultHeader:@"X-AUTH-TOKEN" value:@"abc123"];
    

    You don't need to subclass the AFHTTPClient.