tumblr/tumblr.js

Url path handling isn't compatible with the Tumblr API

nightpool opened this issue · 3 comments

Often, the tumblr API will return a _links object like this:

{
  next: {
    href: '/v2/blog/nightpool.tumblr.com/posts?npf=true&offset=21&page_number=2',
    method: 'GET',
    query_params: { npf: 'true', offset: '21', page_number: '2' }
  }
}

This is most common when paginating API resources, but is occasionally used for other parameters as well. The problem is that if you don't know the endpoint you're trying to hit, you might want to pass the href param to the .getRequest method:

tumblr.getRequest(response._links.next.href);
// GET https://api.tumblr.com/v2/v2/blog/nightpool.tumblr.com/posts?npf=true&offset=21&page_number=2?api_key=[redacted]
// uh-oh!
// let's try this:
const path = response._links.next.href.replace('/v2', '');
tumblr.getRequest(path);
// GET https://api.tumblr.com/v2/blog/nightpool.tumblr.com/posts?npf=true&offset=21&page_number=2%3Fapi_key%3D[redacted]
// That's no good!
// Look at that messed up api_key param!

The only option is to parse the href, extract the path, and then pass it back to tumblr.js with the requisite query parameters. Needless to say, working well with the structured data returned from the API like this is one of the core thing I expect an API library to handle for me! This is also partially a server-side ux bug—if _links had a path parameter alongside the href parameter, that would be a very easy solution to this problem.

cyle commented

Hey @nightpool , thanks for posting this issue. We'll take a look and see what we can do here, that indeed seems very annoying.

cyle commented

potential fix here at the framework level: #100

cyle commented

Cut a new v3.0.0 release to try to help mitigate this issue!