aribouius / jsonapi-react

A minimal JSON:API client and React hooks for fetching, updating, and caching remote data.
MIT License
149 stars 28 forks source link

How to access the response headers? #15

Closed broodfusion closed 3 years ago

broodfusion commented 4 years ago

First of all, awesome library!

My use case is that I am refreshing jwt token on API requests, the new jwt token is set on the response header. Is there a way to access the response header?

Thank you!

aribouius commented 4 years ago

Hey @broodfusion my apologies, I saw your comment a while back and could have sworn I responded to it, but guess not. Right now there's unfortunately not a great way to access a response header, as the library abstracts the request cycle quite a bit.

Passing the response headers through useQuery() or the client.fetch() doesn't appear viable at the moment, as it would be a large breaking change. I'd love to support this somehow though, and finally have some time to dig into it now.

The client instance does implement a basic event subscription system (see here), so I was thinking a decent solution might be to dispatch a new event whenever a request is received, and pass through actual response object.

Thoughts?

aribouius commented 3 years ago

Closing due to inactivity.