1.1.9 • Published 10 years ago

puck v1.1.9

Weekly downloads
15
License
MIT
Repository
-
Last release
10 years ago

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

1.1.9

10 years ago

1.1.8

10 years ago

1.1.7

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.1

11 years ago