GithubHelp home page GithubHelp logo

relay's Introduction

#Usage

//es6
import Relay from 'relay';

var schema = {
   comments: {
       get: {
         path: '/comments',
         // parse is optional
         parse: function(res){
          return res.map(comment => comment + '!!')
         },
         method: 'GET', // optional defaults to GET  
         
      } 
   }
}


var config = {
   apiUrl: 'http://test.com'
}

var relay = Relay.fromSchema(schema, config);
var api = relay.api;

#Plugins

//handler function is called once
//superagent level
Relay.use(function(superagent){

});


//or after creating relay instance
// handler function is called for each request
// 
relay.use(function(request){
  //set accept header
  request.accept('json')
});

#Available Events

Relay extends from EventEmitter, so you can use nodes event api to listen for events

  • beforeRequest: here requests can be modified
  • request: take this as a opportunity to abort requests if needed
  • response
  • error
  • requestsFinish: this is fired when there are 0 pending requests
/*
options = {
    resourceName: 'comments',
    methodName: 'get',
    path: '/comments',
    parse: null 
   } 
*/
relay.on('beforeRequest', function(request){

});

relay.on('request', function(request){

});

relay.on('response', function(request, response){

});

relay.on('error', function(error, request, response){

});

relay.on('requestsFinish', function(){

});

#Api Methods

Api methods returns promises, you can also pass node style callback. Methods are available as lower cased + concatenated(resouceName_methodName)

//with out data 1
var promise = api.comments.get();

//or callback
api.comments.get(function(err, comments, res){
}); 

//with out data 2
var request = api.comments.get(false);
var promise = request.end(); // similar to superagent's api

//or callback
request.end(function(err, comments, res){
});


//with data 1
var promise = api.comments.get({count:3}).then(function(comments, res){});

//or callback
api.comments.get({count:3},function(err, comments, res){
});

//with data 2
var request = api.comments.get({count:3}, false);
var promise = request.end(); // similar to superagent's api

//or callback
request.end(function(err, comments, res){
});

run gulp default task if needed

gulp default

relay's People

Contributors

mailaneel avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

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.