koa-request
wrapper to request library ready to use in koa
Last updated 11 years ago by dionoid .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install koa-request 
SYNC missed versions from official npm registry.

koa-request

Very simple wrapper to the request library for use in koa.
Wraps the request lib as thunk-returning functions for use in kao's middleware generator-functions.

To install simply run:

npm install koa-request

Require koa first and will only work on node v0.11.7 or newer.

You must run node with --harmony flag (--harmony-generators works as well)

node --harmony example.js

Simple example using koa-request in koa:

var koa = require('koa');
var request = require('koa-request');
 
var app = koa();

app.use(function *() {

	var options = {
    	url: 'https://api.github.com/repos/dionoid/koa-request',
	    headers: { 'User-Agent': 'request' }
	};

	var response = yield request(options); //Yay, HTTP requests with no callbacks!
	var info = JSON.parse(response.body);

	this.body = 'my full name is ' + info.full_name;
});

app.listen(process.env.PORT || 8080);

Current Tags

  • 1.0.0                                ...           latest (11 years ago)

2 Versions

  • 1.0.0                                ...           11 years ago
  • 0.0.1                                ...           11 years ago
Maintainers (1)
Downloads
Total 1
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE