by
354 15
3
5
2,783
0
Top 1% !
Famous
Easy-to-find
Specified
OpenSource
Popularity: 5749th place

Published on:

ClassNameWebRestService
Frameworkjax-rs
Languagejava
LicenseMIT_X11
MethodNamegetUser
OutputTypeResponse

JAX-RS web service using Path annotation

This simple code shows how to implement a JAX-RS rest web service.
@Path annotation is used to bind URI pattern to a specific method. 
The web service path '/path' is the main root.
On a GET request to URI '/path' the method getUser() will be invoked.
On a GET request to URI '/path/test' the method getTest() will be invoked.

In this simple java code all GET methods return HTTP 200 OK code using the Response object.

Thanks to http://www.mkyong.com/webservices/jax-rs/jax-rs-path-uri-matching-example/
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/41836/JAX-RS-web-service-using-Path-annotation?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import javax.ws.*; @Path("/path") public class WebRestService { @GET public Response getUser() { return Response.status(200).entity("get User is called").build(); } @GET @Path("/test") public Response getTest() { return Response.status(200).entity("get Test is called").build(); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus