Reactive way of handling HTTP Request/Response
ReactiveXHR.register({
"update_profile" : "/api/user/profile/edit",
"update_trip" : "/api/trip/{code}/update"
})
var rx = new ReactiveXHR();
rx.send("update_profile",{ fname : "Lalit"}).done(function(){
// Not mandatory, but do when done.
});
var rx = new ReactiveXHR();
rx.on("update_profile",function(req, resp){
// update name in header module
});
var rx = new ReactiveXHR();
rx.on("update_profile",function(req, resp){
// update sidebar module
});
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"}
});