How do I access the Response Headers using ServiceStack

Viewed 38

I'm using react with Redux toolkit but I'm unbale to access the Response headers

return await client
.get(new Users())
.then((data) => {

// how to I access the Response Header here?
  console.log("data", data);
  return data;
})
.catch((error) => {

});
1 Answers

I'm assuming you're referring to ServiceStack's TypeScript Service Client, the public API of which you can find on index.d.ts where you can use the instance requestFilter and responseFilter:

export declare class JsonServiceClient {
    //...
    requestFilter: (req: IRequestInit) => void;
    responseFilter: (res: Response) => void;
}

To inspect the underlying W3C fetch API's Request / Response, e.g:

let client = new JsonServiceClient();
client.responseFilter = function(r) {
    console.log(r.headers)
}

client.get(new Users())
    .then(...)
Related