Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

magik-api

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magik-api - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

15

package.json
{
"name": "magik-api",
"version": "0.1.0",
"version": "0.1.1",
"repository": "https://github.com/inmagik/magik-api",
"description": "Fluent API client based on rxjs",
"author": "Giovanni Fumagalli <giovanni.fumagalli@inmagik.com>",
"license": "MIT",
"main": "lib/index.js",
"module": "lib/index.cjs.js",
"bugs": {
"url": "https://github.com/inmagik/magik-api/issues"
},
"keywords": [
"api",
"rxjs",
"rest"
],
"main": "./lib/index.cjs.js",
"module": "./lib/index.es.js",
"types": "./lib/index.d.ts",

@@ -10,0 +19,0 @@ "files": [

121

README.MD
# Magik API
> Fluent API client based on rxjs
> Fluent API client based on rxjs
## Install
```sh
yarn add magik-api
npm install --save magik-api
```
## Usage
```js
// Start building
const api = magikApi()
// Configure a base url
.baseUrl('/v1')
// Enabel tralling slash?
.trailingSlash(true)
// Confgure request
// https://github.com/ReactiveX/rxjs/blob/6.x/src/internal/observable/dom/AjaxObservable.ts#L7
.request({
timeout: 23,
responseType: 'text',
})
// Set query params
.query({
name: 'Mike'
})
// Configure headers
.headers({
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
})
// Map response, default is:
.mapResponse(r => response)
// Configure auth headers default is:
.authHeaders(token => ({
Authorization: token
}))
api.get(
// URL
'/foo',
// Query Params
{ name: 'Arturo' }
)
api.post( // Same .put .patch
// URL
'/foo',
// BODY
{ name: 'Arturo' }
)
// Content-Type headers is set default to: application/json
// or nothing if U give FormData
api.delete(
// URL
'/foo',
// Query Params
{ name: 'Arturo' }
)
// Authenticate a request
api.auth('Secret').get('/me')
// Curry an url
const getHello = api.url('/hello').get // Same for .put, .path, .post, .delete
getHello(
// Query params
{ q: 'best' }
)
// Curry auth on url
const getAuthHello = api.url('/hello').curryAuth().get
getHello('TOKEN')(
// Query params
{ q: 'best' }
)
// Resource
const todosApi = api.resource('/todos')
todosApi.list({ mode: 'dirty' })
// GET /todos?mode=dirty
todosApi.detail(23, { mode: 'dirty' })
// GET /todos/23?mode=dirty
todosApi.create({ mode: 'dirty' })
// POST /todos
todosApi.update(2, { mode: 'dirty' })
// PUT /todos/2
todosApi.partialUpdate(2, { mode: 'dirty' })
// PATCH /todos/2
todosApi.delete(2, { mode: 'dirty' })
// DELETE /todos/2
// ehehe shorcut
todosApi.deleteId(2)
// DELETE /todos/2
// map response to ({ id: 2 }) util for 204 No Content styles responses
// You can use the other methods as well
todosApi.put('/23/toggle')
// PUT /todos/23/toggle
// Curry auth on resource
const todosApiAuth = api.resource('/todos').curryAuth()
todosApiAuth.detail('TOKEN')(33)
// Same for list, detail, update, partialUpdate, delete, deleteId
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc