2.0.0 • Published 3 months ago

protoflower v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

protoflower

import { makeApi } from 'protoflower'

makeApi('swapi', {
    host: 'swapi.dev',
})
makeApi('core', {
    host: 'domain.com',
    endpoint: 'apiv2'
})

// GET requests
let skywalker = await 'people/1'.api('swapi').get()
let himalsobe = await 'people'.api('swapi').get(1)

// POST requests
let response = await 'entity/add'.api('core').post({
    type: 'blog_post',
    title: 'My Best Summer: 2048',
    body: 'I had a really good time.',
}) 

just run node test.js or npm test

requests made in the above code:

GET http://swapi.dev/api/people/1
GET http://swapi.dev/api/people/1
POST http://domain.com/apiv2/entity/add

defaults object:

let defaults = {
    port: 80,
    host: '/',
    protocol: 'http',
    endpoint: 'api'
}

Other shorter prototype:

import { makeShortApi }

makeShortApi({
    endpoint: 'api2',
    port: 8000,
    host: 'localhost'
})

let people = 'users'.get(2) // returns await response.json(), so you don't have to. annoying, I know
let newUser = 'user/create'.post({
    name: 'mynameis'
})

Requests:

GET http://localhost:8000/api2/users/3
POST http://localhost:8000/api2/user/create
2.0.0

3 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago