1.1.9 • Published 9 years ago
puck v1.1.9
About
puck is a library for any terminal request and response. which aims to be a lightweight, cross-terminal, onion-middleware network-io engine
Features
- cross terminal and lightweight api
- base on Fetch and Promise api
- onion-middleware system
Installation
npm install puckApi
Static property
Puck.version
return Puck library version
Puck.middlewares
return middlewares list
Puck.applyMiddlewares(midwares)
load midwares
new Puck(options)
debug{boolean} : debug modeenv{string} : run dev
Instance Api
use(middleware)
async functions (Babel required)
puck.use(async (ctx,next){
// req process
await next();
// res process
});request(url,options)
method{string} : request method,default isGETjsonp{boolean}: jsonp requestheaders{object} : request headers objectbody: request body, Supportstring,formdata,credentials{string} : Sending cookies,optionalsame-originorincludetype{string}: response body content-type.optionaljson,html,text,blob
Convenience methods
get puck.get(url)
post puck.post(url,options)
put puck.put(url,options)
delete puck.delete(url)
Example
const puck = new Puck();
puck.use(async (ctx,next){
ctx.req.url = 'xxx';
await next();
// res process
});
puck.get('/xxx/yyy')
.then()
.catch()License
MIT