Echo JS 0.11.0

<~>
tracker1 2088 days ago. link parent 2 points
Yeah, it's a mixed bag, I usually wrap it up in something that works with my API structure better... (posting a gist to link now).  The normalizeRequest[1] default export handles a lot of the issues for me. (note using elvis operator[2] via babel).

With that in place, a lot of my api-client comes down to things like:

    import callAPI, { headRequest } from './request';

    export const check = id =>
      headRequest(`/petition/${encodeURIComponent(id.toUpperCase())}`).then(
        r => r && r.statusCode === 200
      );

    export const dashboard = id =>
      callAPI('GET', `/petition/${encodeURIComponent(id.toUpperCase())}/dashboard`);

    export const create = petition => callAPI('POST', '/petition', petition);


[1] https://gist.github.com/tracker1/0b0522b840573171edffd31df50b381a

[2] https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining

Replies