Hi can anyone past some code how to do a restful web service get and post method. This would be server side so I would be able to invoke the two services from a client.
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assume you have a script index.php. You might have two functions inside of it,
showForm()andhandleForm().Assume a request comes in to index.php.
There you have it. REST. If you send a GET request to index.php, you’ll show some output, and if you send a POST request to index.php, you’ll perform some data manipulation. You can take if from there for the other RESTful HTTP request types, such as DELETE, etc.
Obviously this is a very simple example, and I wouldn’t want to create an entire site in this manner. It’s best to go about creating a RESTful site in an architecturally sound way. Many frameworks can assist with this.
REST is a hot topic right now, it seems everyone wants their apps to be RESTful. There’s a lot of articles and guides out there on Google, you’d probably do well to spend some time researching various approaches.
Note about URLs: URIs don’t have to be pretty to be RESTful. However, a key point of REST is that all URIs should represent a single resource. As query parameters are not part of a URI, “
/index.php?show=2” is not considered RESTful. You’ll find that a lot of applications use URL rewriting to convert query parameters into something like “/index/2” instead.That being said, there’s nothing wrong with having “/index.php” as a URI, just as long as it only represents a single state.