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
putmethod 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
bodyof the response.- If you want to return the full
responseobject from Axios instead, setapi.returnBody = false.
- If you want to return the full
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.
MIT