RestAPI is a standalone rest client for javascript. If you find anything messy ? report me
Basic example
var a = new jaffy.restAPI();
a.setUrl("http://yourresturl");
a.GET(function(response){
console.log(response);
});
setUrl(url)
you can define relative or absolute url.
- GET
- POST
- OPTIONS
- PUT
- DELETE
- PATCH
- setHeader(variable, value)
for example
var a = new jaffy.restAPI();
a.setUrl("http://yourresturl");
a.setHeader("Authorization", "Bearer AJDYOWOJMXL273jsiJs72js82==");
a.GET(function(response){
console.log(response);
});
- setParam(variable, value)
for example
var a = new jaffy.restAPI();
a.setUrl("http://yourresturl");
a.setParam("test", "1234");
a.GET(function(response){
console.log(response);
});
- setBody(variable, value)
for example
var a = new jaffy.restAPI();
a.setUrl("http://yourresturl");
a.setBody("test", "1234");
a.POST(function(response){
console.log(response);
});
- setParam(variable, value)
for example
var a = new jaffy.restAPI();
a.setUrl("http://yourresturl");
a.setPayload("test", "1234");
a.POST(function(response){
console.log(response);
});
Note: setParam() & setBody() will not work with only POST methods. also rest will be used as payload once you started using setParam()
sync(true|false)
use to make syncronous rest request. but this feature will block the execution of main thread. use only if it is really necessary.