Magik API
Fluent API client based on rxjs
Install
yarn add magik-api
npm install --save magik-api
Usage
const api = magikApi()
.baseUrl('/v1')
.trailingSlash(true)
.request({
timeout: 23,
responseType: 'text',
})
.query({
name: 'Mike'
})
.headers({
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
})
.mapResponse(r => response)
.authHeaders(token => ({
Authorization: token
}))
api.get(
'/foo',
{ name: 'Arturo' }
)
api.post(
'/foo',
{ name: 'Arturo' }
)
api.delete(
'/foo',
{ name: 'Arturo' }
)
api.auth('Secret').get('/me')
const getHello = api.url('/hello').get
getHello(
{ q: 'best' }
)
const getAuthHello = api.url('/hello').curryAuth().get
getHello('TOKEN')(
{ q: 'best' }
)
const todosApi = api.resource('/todos')
todosApi.list({ mode: 'dirty' })
todosApi.detail(23, { mode: 'dirty' })
todosApi.create({ mode: 'dirty' })
todosApi.update(2, { mode: 'dirty' })
todosApi.partialUpdate(2, { mode: 'dirty' })
todosApi.delete(2, { mode: 'dirty' })
todosApi.deleteId(2)
todosApi.put('/23/toggle')
const todosApiAuth = api.resource('/todos').curryAuth()
todosApiAuth.detail('TOKEN')(33)