0

I am writing a java application which invokes a web service and uses its response text. (i.e.) it invokes a URL like http://web-server.com/item/3455

That URL would return a response text (string) like "nexus".

For implementing the above functionality, is there any readily available framework that we can make use of? Or should I code the functionality from scratch.

Thanks.

3 Answers 3

2

Even if the API is not strictly RESTful, you can use spring-web's RestTemplate like so:

RestTemplate restTemplate = new RestTemplate();
String response = restTemplate.getForObject("http://web-server.com/item/3455", String.class);
Sign up to request clarification or add additional context in comments.

4 Comments

thanks. that looks really cool, I am just wondering if there could be a lighter option (a smaller framework).
Could you provide the maven dependency for this jar? many thanks.
If you're using Maven, it's in the central repo (search.maven.org/#search|ga|1|spring-web).
The lightest option per my experience is to use apache http client to make a request and capture response, and dont bother whether its webservice/restful or not.
1

Based on url, it seems you are doing REST call. You may use HTTPURLConnection API.

1 Comment

thanks. Could we use this for non-rest web services as well? For example, if the URL is like web-server.com/item?id=3455
1

All you need is a simple HTTP client to do what you're talking about. The HttpClient project from Apache is a popular choice and would certainly work for what you're trying to do.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.