unsplash / unsplash-js

🤖 Official JavaScript wrapper for the Unsplash API
https://www.npmjs.com/package/unsplash-js
MIT License
2.15k stars 157 forks source link

Access Response headers from API calls #176

Closed all-things-liquid closed 3 years ago

all-things-liquid commented 3 years ago

I recently upgraded to the 7.0.10 version of the package to get TypeScript typing. But I can't find a way to access response headers from API calls, since I only get an object of type ApiResponse.

I need to get access to rate limit information inside my code, and used to be able to do that with the 6.3.0 version:

const remainingRequests = parseInt(response.headers._headers['x-ratelimit-remaining'][0])
const limitRequests = parseInt(response.headers._headers['x-ratelimit-limit'][0])

Is there another way I can have access to this?

OliverJAsh commented 3 years ago

With 7449cecff89d14d660ac432181356cb461fd82f6 you should be able to do this:

const api = createApi({ accessKey: 'MY_ACCESS_KEY' });
api.topics.get({ topicIdOrSlug: 'foo' }).then(apiResponse => {
  apiResponse.originalResponse.headers.get('content-type');
});
OliverJAsh commented 3 years ago

https://github.com/unsplash/unsplash-js/releases/tag/v7.0.11