puck

1.1.9 • Public • Published

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 mode
  • env{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 is GET
  • jsonp{boolean}: jsonp request
  • headers{object} : request headers object
  • body : request body, Supportstring,formdata,
  • credentials{string} : Sending cookies,optional same-origin or include
  • type{string}: response body content-type.optional json ,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

Readme

Keywords

none

Package Sidebar

Install

npm i puck

Weekly Downloads

1

Version

1.1.9

License

MIT

Last publish

Collaborators

  • playman