uveng
uveng

Reputation: 71

How to pass argument to a REST method

I have created simple rest service @GET and takes 2 parameters username and password. I m trying to search how to pass parameters through rest service client and how to get it using the method. I am unable to get the exact answer I want.

How can I pass parameters and how to use that in my webservice?

Upvotes: 0

Views: 721

Answers (2)

Alex Stybaev
Alex Stybaev

Reputation: 4693

You should look on something like: @HeaderParam or @PathParam

in Jersey it looks like:

 @Get
    @Path("/mywebservice")
    public Response myWebService(@HeaderParam String username, 
                                 @HeaderParam String password)
    {
    ...
    }

but you should remember that this way of sending/receiving username and password isn't too secure ;)

Upvotes: 0

codeisee
codeisee

Reputation: 1742

I don't know what framework you are using but if you use Spring, you can do it like this:

@Controller
public class SampleController {

@RequestMapping(value="/test/{name}/{password}", method = RequestMethod.GET)
public String doTest(@PathVariable String name,@PathVariable String password, ModelMap model) {
    System.out.println("REST paras name:"+name+",password:"+password);
    return "samplePage";
}
}

then ,url path like [/test/{name}/info] [/test/{name}/info.*] [/test/{name}/info/] will pass to this method!

Upvotes: 1

Related Questions