Question

I am pretty new to REST and Web Applications in general. I need to implement a REST call that adds more resources to the system. Some of the resources can be created by only an XML like a Folder. I am guessing it would be a PUT request and in the body to put the XML that describes the resource and on the server to process the request and create the Folder. Some resources require to be described (what it is, to who it belongs .. etc) and also to provide a file. for example an image.

i have few questions: 1. what is the best practice to handle httpServletRequest? it seem a little cumbersome object, i have read about HttpClient but i am not sure. 2. It sounds like a very common task in that every RESTful server is doing. is there a good tutorial/guide for it?

thanks

Was it helpful?

Solution

I have few questions: 1. what is the best practice to handle httpServletRequest? it seem a little cumbersome object, i have read about HttpClient but i am not sure.

Assuming you are using Java you have several options here to implement a rest client. You can use the Apache HTTP Client, Spring RestTemplate, Jersey, to name a few. Next you need to find out the media type - is it xml, json, plain text, etc. This is how you would pass the data in the body of your request to the rest service. You will also need to find out how the service handles authorization. Are they using HTTP Basic, Digest, etc. If they are using XML, then you will need to get familiar with JAXB or a similar marshaller/un-marshaller to make life easy for you.

2.It sounds like a very common task in that every RESTful server is doing. is there a good tutorial/guide for it?

There are many tutorials for it. I personally like using the Spring Rest Template, however, you can use any framework you like. Here are some good tutorial links:-

Spring Rest Template (uses Apache HTTP client behind the scene):

Jersey:

Apache HTTP Client:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top