brianleroux / tiny-json-http

:anchor: Minimalist HTTP client for JSON payloads.
172 stars 18 forks source link

Working with headers in result #1

Closed neurotech closed 7 years ago

neurotech commented 7 years ago

Hi @brianleroux

Is there any way to "get" the headers of the result returned by tiny-json-http? Below is some example code that may help explain my question:

tiny.get(options, function (err, result) {
  if (err) {
    console.error(err);
  }
  if (result.headers.link) {
    console.log('Link header present.');
  } else {
    console.log('No Link header present.');
  }
});
brianleroux commented 7 years ago

I really debated this and decided I'd wait and see if someone wanted it! 1/2

brianleroux commented 7 years ago

How do you think it should work? Could see the return object being {headers, body} maybe?

neurotech commented 7 years ago

That sounds great to me. In my mind's eye I see something like:

{
  headers: {
    date: 'foo',
    link: 'baz',
    ...
  },
  body: [...]
}
brianleroux commented 7 years ago

another way, backwards compatible (tho idc about that hugely as its such a small lib)

tiny.get(options, function _got(err, body, headers) {
  console.log({err, body, headers})
})
neurotech commented 7 years ago

I just tried that, and got this in return:

{
  err: null,
  body: [...],
  headers: undefined
}
brianleroux commented 7 years ago

oh ya! that doesn't exist yet / just brainstorming!! wanna get @ednapiranha's feedback too

neurotech commented 7 years ago

Ah my apologies I misunderstood.

neurotech commented 7 years ago

@brianleroux do you have a rough idea of how long it will take to get this implemented? (Just planning ahead with regards to a Christmas project). Please let me know as soon as you can.

brianleroux commented 7 years ago

oh sorry / I'll gotcha something today promise! 💯

brianleroux commented 7 years ago

Aight @neurotech just published 🌟 shiny 5.0with support for {body, headers} in the callback continuation result. Hope this helps!

neurotech commented 7 years ago

Thank you so much, you are top shelf! ✨