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

Feature/typescript #143

Closed samijaber closed 3 years ago

samijaber commented 3 years ago

Overview

TO-DO

samijaber commented 3 years ago

Outside of the methods we don't implement, are there any breaking changes?

There's more! It's pretty much all changed. I'll need to write up a new readme of course. Biggest things:

A very quick overview of how to consume response from the new API:

const api = Unsplash({ accessKey: 'abc123' });

api.photos.get({ photoId: 'foo' }).then(result => {
  if (result.type === 'error') {
    console.log('error occurred: ', result.errors[0]);
  } else if (result.type === 'aborted') {
    console.log('fetch request aborted');
  } else {
    console.log('received photo: ', result.response);
  }
});

One other thing I am also adding is for feed methods: the lib will automatically handle extracting the total from x-total header and return that along with the JSON body (e.g. result.response.feed and result.response.total) as that's annoying manual work that any Unsplash API consumer that shows a feed will likely need for the sake of pagination.

lukechesser commented 3 years ago

@samijaber cool, we'll need to create an upgrade guide to go with the new README as well. Something that tells people how to go from the old methods to the new ones, and any 'gotchas'