I’ve tried searching but I can’t figure out how to access data via a RESTful interface. I’m looking for just example code that shows someone access some data from some imaginary web service using its API. A simple “how-it-works” explanation would be helpful too.
Share
Kind of a hot topic. Expect an explosion of answers 😉
REST works on the principle of using HTTP request methods to determine an application’s (the REST server) action on an object. The 4 HTTP methods commonly used are GET, POST, PUT and DELETE.
Say, for example, the object in question is user data. The REST url/object might look something like http://mydomain.com/services/user
If we wanted to get information about existing user, you could
GET http://mydomain.com/services/user/someuserid.If we wanted to create a user, you would use
POST http://mydomain.com/services/userand the request body would contain the user’s information.If we wanted to change a user’s info, you would use
PUT http://mydomain.com/services/user/someuserid. Again, the request body would contain the user’s new information.If we wanted to delete a user, you would use
DELETE http://mydomain.com/services/user/someuseridIn summary, the 4 different HTTP methods generally have these meanings, but can differ from server to server, depending on how RESTful it is: