0.2.0 • Published 8 years ago
micro-api v0.2.0
Micro API
Summary
Minimal routing layer for building JSON APIs with Zeit's Micro
Installation
yarn add micro micro-api
Usage
Declare your API's routes
// index.js
const microApi = require('micro-api')
const handlers = require('./handlers')
const api = microApi([
{
method: 'post',
path: '/foos',
handler: handlers.createFoo,
},
{
method: 'get',
path: '/foos/:fooId',
handler: handlers.showFoo,
},
])
module.exports = api
Define some micro-compatible handlers
// handlers.js
const uuid = require('uuid')
// In memory database
const foos = []
const createFoo = ({ body }) => {
// Build up the new item
const newFoo = { ...body, id: uuid() }
// Add it to the database
foos.push(newFoo)
return newFoo
}
// Find and return by id
const showFoo = ({ params: { fooId } }) => foos.find(f => f.id === fooId)
module.exports = { createFoo, showFoo }
Run
micro -p 3000 ./index.js
See Micro documentation for complete usage.
0.2.0
8 years ago
0.1.6
8 years ago
0.1.5
8 years ago
0.1.4
8 years ago
0.1.3
8 years ago
0.1.2
8 years ago
0.1.1
8 years ago
0.1.0
8 years ago
0.0.13
8 years ago
0.0.12
8 years ago
0.0.11
9 years ago
0.0.10
9 years ago
0.0.9
9 years ago
0.0.8
9 years ago
0.0.7
9 years ago
0.0.6
9 years ago
0.0.5
9 years ago
0.0.4
9 years ago
0.0.3
9 years ago
0.0.2
9 years ago
0.0.1
9 years ago