Skip to content

Repository files navigation

@dimensionalpocket/api-client

build

Generic API client for Node apps to send requests to Rails APIs developed by the studio.

Included:

Opinionated settings:

  • Query string format follows Rails conventions
  • PUT is not supported: there's a put method but it's converted to PATCH
  • Timeout defaults to 45 seconds to account for APIs hosted on Heroku
    • Can be overwritten in the constructor
  • It returns the body of the response.
    • If you want to return the full response object from Axios instead, set api.returnBody = false.

Usage

varapi=newApiClient("https://exampleapi.com")// GET /things?param=1api.get('/things',{param: 1}).then(body=>{})// POST /thingsapi.post('/things',{description: 'something'}).then(body=>{})// PATCH /things/1api.put('/things/1',{description: 'new thing'}).then(body=>{})api.patch('/things/1',{description: 'new thing'}).then(body=>{})// DELETE /things/1api.delete('/things/1').then(body=>{})// OPTIONS /things/1api.request('OPTIONS','/things/1').then(body=>{})

Other workflows (such as error capture) follow Axios conventions.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages