puck
v1.1.9
Published
lightweight cross-terminal onion-middleware network io engine
Downloads
522
Readme
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 puck
Api
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 isGET
jsonp
{boolean}: jsonp requestheaders
{object} : request headers objectbody
: request body, Supportstring
,formdata
,credentials
{string} : Sending cookies,optionalsame-origin
orinclude
type
{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