...
Code Block | ||||
---|---|---|---|---|
| ||||
@Path("/user") public class UserRestServices { private String genPassword() @GET @Path("/sayhello") @Produces(MediaType.TEXT_HTML) public String sayHtmlHelloTest() // Test entry point, call this from url in browser to make sure service up and running @GET @Path("/cu/{user}") @Produces(MediaType.APPLICATION_JSON) public Response createUser(@PathParam("user") String userId) // create a user from url in browser, calls __createUser @POST @Path("/cufocu") @Consumes(MediaType.APPLICATION_JSON) public Response createUserFromObject(User usr) // create a user from java marshalled object, calls __createUser private Response __createUser( User usr ) // actually makes call to DB @POST @Path("/du") @Consumes(MediaType.APPLICATION_JSON) public Response deleteUser(User us) // deletes a user if they exist in DB @POST @Path("/uu/{user}") @Consumes(MediaType.APPLICATION_JSON) public Response updateUser(User us) // updates a user if they exist in DB @GET @Path("/fu/{user}/{pwd}") @Produces(MediaType.APPLICATION_JSON) public Response findUser(@PathParam("user") String userId, @PathParam("pwd") String pwd) // finds a user if they exist in the DB } |
...
<base uri>/user/cu
<base uri>/user/cu/{userid}
<base uri>/user/fu
<base uri>/user/fu/{userid}/{pwd}
<base uri>/user/uu
<base uri>/user/uu/{userid}
<base uri>/user/du/
<base uri>/user/du/{userid}
The URIs that don't have a parameter are used in service to service interactions passing JSON strings. For each of these interactions, the simplest way to specify the contract is through a Java class.