How to use request-compose - 10 common examples

To help you get started, we’ve selected a few request-compose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simov / grant / lib / client.js View on Github external
// some providers return wrong `content-type` like: text/html or text/plain
  else {
    try {
      body = JSON.parse(body)
    }
    catch (err) {
      // use qs instead of querystring for nested objects
      body = qs.parse(body)
    }
  }

  return {options, res, body, raw}
}

module.exports = require('request-compose').extend({
  Request: {oauth: require('request-oauth')},
  Response: {parse}
}).client
github simov / grant / examples / jwt / app.js View on Github external
var express = require('express')
var session = require('express-session')
var grant = require('grant-express')
var request = require('request-compose').client
var jwt = require('./jwt')


express()
  .use(session({name: 'grant', secret: 'grant', saveUninitialized: true, resave: true}))
  .use(grant(require('./config.json')))

  .get('/hello', async (req, res) => {
    var {body} = await request({
      url: 'https://graph.facebook.com/v2.12/me',
      headers: {authorization: `Bearer ${req.session.grant.response.access_token}`}
    })
    // remove the session data
    req.session.destroy(() => {
      // remove the cookie
      res.clearCookie('grant')
github simov / grant / test / consumer / flow.js View on Github external
var t = require('assert')

var request = require('request-compose').extend({
  Request: {cookie: require('request-cookie').Request},
  Response: {cookie: require('request-cookie').Response},
}).client

var hapi = parseInt(require('hapi/package.json').version.split('.')[0])

var port = {auth: 5000, app: 5001}
var url = {
  auth: (path) => `http://localhost:${port.auth}${path}`,
  app: (path) => `http://localhost:${port.app}${path}`,
}

var provider = require('./util/provider')
var client = require('./util/client')
github simov / grant / test / consumer / session.js View on Github external
var t = require('assert')

var request = require('request-compose').extend({
  Request: {cookie: require('request-cookie').Request},
  Response: {cookie: require('request-cookie').Response},
}).client

var hapi = parseInt(require('hapi/package.json').version.split('.')[0])

var port = {oauth1: 5000, oauth2: 5001, app: 5002}
var url = {
  oauth1: (path) => `http://localhost:${port.oauth1}${path}`,
  oauth2: (path) => `http://localhost:${port.oauth2}${path}`,
  app: (path) => `http://localhost:${port.app}${path}`,
}

var provider = require('./util/provider')
var client = require('./util/client')
github simov / grant / test / client.js View on Github external
it('extend', async () => {
      var {body} = await request({url: 'http://localhost:5000/qstext'})
      t.deepStrictEqual(body, {nested: {querystring: 'true'}})
      var {body} = await compose.client({url: 'http://localhost:5000/qstext'})
      t.equal(body, 'nested%5Bquerystring%5D=true')
    })
github simov / grant / test / consumer / error.js View on Github external
var t = require('assert')
var urlib = require('url')
var http = require('http')
var qs = require('qs')

var request = require('request-compose').extend({
  Request: {cookie: require('request-cookie').Request},
  Response: {cookie: require('request-cookie').Response},
}).client

var express = require('express')
var session = require('express-session')

var Koa = require('koa')
var koasession = require('koa-session')
var mount = require('koa-mount')
var convert = require('koa-convert')
var koaqs = require('koa-qs')

var Hapi = require('hapi')
var yar = require('yar')
github simov / grant / test / consumer / middleware.js View on Github external
var t = require('assert')

var request = require('request-compose').extend({
  Request: {cookie: require('request-cookie').Request},
  Response: {cookie: require('request-cookie').Response},
}).client

var port = {oauth2: 5001, app: 5002}
var url = {
  oauth2: (path) => `http://localhost:${port.oauth2}${path}`,
  app: (path) => `http://localhost:${port.app}${path}`,
}

var provider = require('./util/provider')
var client = require('./util/client')


describe('middleware', () => {
  var server = {oauth2: null}
github simov / request-compose / examples / basic-client.js View on Github external
var request = require('request-compose').client

;(async () => {
  try {
    var {res, body} = await request({
      url: 'https://api.github.com/users/simov',
      headers: {
        'user-agent': 'request-compose'
      }
    })
    console.log(res.statusCode, res.statusMessage)
    console.log(res.headers['x-ratelimit-remaining'])
    console.log(body)
  }
  catch (err) {
    console.error(err)
  }
github simov / request-compose / examples / basic-middlewares.js View on Github external
var compose = require('request-compose')
var Request = compose.Request
var Response = compose.Response

;(async () => {
  try {
    var {res, body} = await compose(
      Request.defaults({headers: {'user-agent': 'request-compose'}}),
      Request.url('https://api.github.com/users/simov'),
      Request.send(),
      Response.buffer(),
      Response.string(),
      Response.parse(),
    )()
    console.log(res.statusCode, res.statusMessage)
    console.log(res.headers['x-ratelimit-remaining'])
    console.log(body)
  }
github simov / request-compose / examples / basic-middlewares.js View on Github external
var compose = require('request-compose')
var Request = compose.Request
var Response = compose.Response

;(async () => {
  try {
    var {res, body} = await compose(
      Request.defaults({headers: {'user-agent': 'request-compose'}}),
      Request.url('https://api.github.com/users/simov'),
      Request.send(),
      Response.buffer(),
      Response.string(),
      Response.parse(),
    )()
    console.log(res.statusCode, res.statusMessage)
    console.log(res.headers['x-ratelimit-remaining'])
    console.log(body)
  }
  catch (err) {

request-compose

Composable HTTP Client

Apache-2.0
Latest version published 3 months ago

Package Health Score

67 / 100
Full package analysis