Skip to content

webmodule/ReactiveXHR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

ReactiveXHR

Reactive way of handling HTTP Request/Response

Basic Use of APIs should be like this

Register API Keys

ReactiveXHR.register({
  "update_profile" : "/api/user/profile/edit",
  "update_trip" : "/api/trip/{code}/update"
})

In Module 1 : Profile Edit Module

var rx = new ReactiveXHR();

rx.send("update_profile",{ fname : "Lalit"}).done(function(){
  // Not mandatory, but do when done.
});

In Module 2 : Header Module

var rx = new ReactiveXHR();

rx.on("update_profile",function(req, resp){
  // update name in header module
});

In Module 3 : Sidebar Module

var rx = new ReactiveXHR();

rx.on("update_profile",function(req, resp){
 // update sidebar module
});

More possible options

rx.send("update_trip",{ rider_name : "Ramo"}, { "code" : "002" });

//Possible ways to subscribe
rx.on("update_trip",function(req, resp, meta){
 // do something 
});
rx.on("update_trip/code=002",function(req, resp, meta){
 // do something based on metadata values
});
rx.on("update_trip?rider_name=Ramo",function(req, resp, meta){
 // do something based on request values
});
rx.on("update_trip#rider_name=Ramo",function(req, resp, meta){
  //do something based on response values
 // assuming response is if format { rider_name : "Ramo"}
});

About

Reactive way of handling HTTP Request/Response

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published