Giter Site home page Giter Site logo

afrostream-node-client-backend's Introduction

Description

wrapper around the backend
this wrapper will handle backend api auth for you

default header behavior is :

  • fwd user agent
  • fwd user ip
  • fwd content type

Usage

create client

var Client = require('afrostream-node-client-backend');
var client = new Client({
  apiKey: "42424242",
  apiSecret: "42424242"
});

request the backend api

client.get('/api/movies')
  .then(
  function success(body) {
    res.json(body);
  },
  function (error) {
    res.status(error.statusCode).json({error: error.message});
  });
client.get('/auth/geo').then(...);
client.post('...');
client.put('...');
client.delete('...');

you can overwrite the oauth bearer token using options

client.get('/api/movies', { token: '42424242' }).then(function success(body) { });

you can overwrite request options using options

client.get('/api/movies', { method: 'POST' }).then(...);

request backend fwding input req infos

client.get('/api/movies', { req: req }).then(...); // will add x-forwarded-user-ip & content-type header

request backend without auth

client.get('/api/movies', { token: null }).then(...);

proxy requests to the backend

client.proxy(req, res);
client.proxy(req, res, { qs: { foo: "bar" }, token: null });

proxy default behavior : do not follow redirect.

fwd response

client.get('/api/movies').nodeify(client.fwd(res));

low level requests

client.request({uri:'/api/movies'}).then(function (data) {
    var response = data[0];
    var body = data[1];
}, function (err) {
    // network errors.
    console.error(err.message);
});

high level requests

client.custom({method: 'GET', uri: '/api/movies'}).then(function (body) {
    // only 200OK responses
    console.log(body)
}, function (err) {
    // 403, 500, ... errors + network errors
    res.status(err.statusCode).json({error: err.message});
    console.error(err.message);
});

afrostream-node-client-backend's People

Contributors

syndr0m avatar

Watchers

 avatar  avatar  avatar

afrostream-node-client-backend's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.