I've built a REST webservice with some webmethods. But I don't get it to work passing parameters to these methods.
I.E.
@GET
@Path("hello")
@Produces(MediaType.TEXT_PLAIN)
public String hello(String firstName, String lastName){
return "Hello " + firstname + " " + lastname
}
How would I invoke that method and how to pass the parameters firstname and lastname? I tried something like this:
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
ClientResponse response = service.path("hello")
.accept(MediaType.TEXT_PLAIN).put(ClientResponse.class);
But where do I add the parameters?
Thank you for your help, best regards, Chris
Parameters and ArgumentsInformation can be passed to methods as parameter. Parameters act as variables inside the method.
The code for REST APIs can be written in multiple languages but Java Programming Language due to its “write once run anywhere” quality is preferred for creating these APIs. This article will introduce you to the Java Programming Language and REST APIs along with their key features.
If you are using SpringMVC for REST api development you can use
@RequestParam("PARAMETER_NAME");
In case of jersey you can use
@QueryParam("PARAMETER_NAME");
Method look like this
public String hello(@RequestParam("firstName")String firstName, @RequestParam("lastName")String lastName){
return "Hello " + firstname + " " + lastname
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With