okay so i have created restful webservice.now how to create a path for a user "abc".
Something like this
http://stackoverflow.com/user/abc
Following is my form for getting the user input thorugh html
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newUser(
@FormParam("uname") String uname,
@FormParam("password") String password,
@Context HttpServletResponse servletResponse
) throws IOException {
User u = new User(uname,password);
User.userdata.put(uname,password);
}
How to make a URI something like this from the form parameters if user has uname as "abc"
http://mysite/user/abc
Use the
@Path
and@PathParam
annotations:If you
PUT
to/user/joe
with a body ofs3cret
, thenuname
will bejoe
andpassword
will bes3cret
.I use
PUT
because the URL you want to use implies that the username is set by the client./user
is the collection resource of all users.Edit: Since this method will change the server state by creating a new user,
PUT
orPOST
must be used.GET
must not change the server state.