Note: I still work on text, code example should be fine.
REST is the one of the most popular interfaces on the web today. One part to its success it owes to its simplicity.
How number of sites that support REST grows we will need some fast and good solution to use those services on client side. Even if its possible to do it all, since REST is based on http, with old AJAX calls, it would be nice to have some little more...
This is one approach that i choose. I create in javascript new object that has six methods five for REST methods, four for POST, PUT, GET and REMOVE plus one more to GET all resources, and one more to get html template to display your data.
This code is based on jquery and json js libs.
Later you will just need to extend your rest service with your url and use it.
After that you can use in your code like this:
Please tell me what do you think about it, and,,,,
REST is the one of the most popular interfaces on the web today. One part to its success it owes to its simplicity.
How number of sites that support REST grows we will need some fast and good solution to use those services on client side. Even if its possible to do it all, since REST is based on http, with old AJAX calls, it would be nice to have some little more...
This is one approach that i choose. I create in javascript new object that has six methods five for REST methods, four for POST, PUT, GET and REMOVE plus one more to GET all resources, and one more to get html template to display your data.
This code is based on jquery and json js libs.
function RestServiceJs(newurl) { this.myurl = newurl; this.add = function(model, callback) { $.ajax({ type: 'POST', url: this.myurl, data: JSON.stringify(model), // '{"name":"' + model.name + '"}', dataType: 'text', processData: false, contentType: 'application/json', success: callback, error: function(req, status, ex) {}, timeout:60000 }); }; this.update = function(model, callback) { $.ajax({ type: 'PUT', url: this.myurl, data: JSON.stringify(model), // '{"name":"' + model.name + '"}', dataType: 'text', processData: false, contentType: 'application/json', success: callback, error: function(req, status, ex) {}, timeout:60000 }); }; this.find = function(id, callback) { $.ajax({ type: 'GET', url: this.myurl + '/' + id, contentType: 'application/json', success: callback, error: function(req, status, ex) {}, timeout:60000 }); }; this.findAll = function(callback) { $.ajax({ type: 'GET', url: this.myurl, contentType: 'application/json', success: callback, error: function(req, status, ex) {}, timeout:60000 }); }; this.remove = function(id, callback) { $.ajax({ type: 'DELETE', url: this.myurl + '/' + id, contentType: 'application/json', success: callback, error: function(req, status, ex) {}, timeout:60000 }); }; this.loadTmpl = function(turl, callback) { $.ajax({ url: turl, success: callback, error: function(req, status, ex) {}, timeout:60000 }); } }
Later you will just need to extend your rest service with your url and use it.
After that you can use in your code like this:
var carRestServiceJs = new RestServiceJs('/rest/car'); // add update event $("a.update_link").click(function() { carRestServiceJs.find(this.id, function(data) { loadAddModel(data); $("#modelName").val(data.name); }); });
Please tell me what do you think about it, and,,,,
Comments
However I think you've inverted two ajax parameters : contentType and dataType.
- contentType : "When sending data to the server, use this content-type."
- dataType : "The type of data that you're expecting back from the server".
So when you're making a GET/DELETE request, you should specify dataType : 'json' or 'html' and not contenType : 'application/json' as you're not sending data to the server.
can you send me the full code please ?
Is this code works same like the chrome advance rest client extention ?
please provide me reference where I can learn to make rest client
lg mobile service center in chennai
lg mobile service center
lg mobile service chennai
python training in bangalore
Excel Training in Chennai
Advanced Excel Training in Chennai
Unix Training in Chennai
Oracle Training in Chennai
Tableau Training in Chennai
Linux Training in Chennai
Social Media Marketing Courses in Chennai
Power BI Training in Chennai
Excel Training in Porur
Excel Training in OMR
I feel very grateful that I read this. It is very helpful and very informative and I Python classes in pune really learned a lot from it.
spark interview questions
AWS Training in Chennai
AWS Training in Bangalore
AWS Training in BTM
AWS Training in Marathahalli
Best AWS Training in Marathahalli
PHP Training in Bangalore
Spoken English Classes in Bangalore
Best AWS Training in Bangalore
Data Science Courses in Bangalore
DevOps Training in Bangalore
devops training in chennai | devops training in anna nagar | devops training in omr | devops training in porur | devops training in tambaram | devops training in velachery
AWS training in Chennai
AWS Online Training in Chennai
AWS training in Bangalore
AWS training in Hyderabad
AWS training in Coimbatore
AWS training
AWS online training
java training in chennai
java training in omr
aws training in chennai
aws training in omr
python training in chennai
python training in omr
selenium training in chennai
selenium training in omr
hardware and networking training in chennai
hardware and networking training in tambaram
xamarin training in chennai
xamarin training in tambaram
ios training in chennai
ios training in tambaram
iot training in chennai
iot training in tambaram
sap training in chennai
sap training in porur
azure training in chennai
azure training in porur
cyber security course in chennai
cyber security course in porur
ethical hacking course in chennai
ethical hacking course in porur
angular js training in chennai
angular js training in velachery
full stack training in chennai
full stack training in velachery
php training in chennai
php training in velachery
photoshop training in chennai
photoshop training in velachery
sap training in chennai
sap training in annanagar
azure training in chennai
azure training in annanagar
cyber security course in chennai
cyber security course in annanagar
ethical hacking course in chennai
ethical hacking course in annanagar
acte chennai
acte complaints
acte reviews
acte trainer complaints
acte trainer reviews
acte velachery reviews complaints
acte tambaram reviews complaints
acte anna nagar reviews complaints
acte porur reviews complaints
acte omr reviews complaints
Easy way to earn money online tips and tricks
Earn money online tips and tricks
Earn money online without investments
Affliate Marketing websites to earn money
DevOps Training
DevOps Online Training
DevOps Online Training in Hyderabad
DevOps Online Training institute
DevOps Training Online
DevOps Online Course
Data Science Training in Chennai