tkh44 / holen

Declarative fetch for React
MIT License
150 stars 16 forks source link

`type` as a function #25

Open jamesplease opened 6 years ago

jamesplease commented 6 years ago

Many enterprisey APIs don't respect the Accept header, so even if you specify JSON you may get something else entirely back. i.e.; old Java/Apache web servers frequently return text stack traces for any error.

It's convenient to be able to dynamically specify the type based on this.

i.e.;

// this API returns stack trace errors ;.;
type(response) {
  return response.ok ? 'json' : 'text';
}

Related: #24


(I know I've been opening a million issues. I plan to resolve them! Lots to do...I'll get to it :v: )