Here, you have a question when you heard first time about JAX-RS. What is JAX-RS?
When you will face an interview for Java
Developer Position in IT Company, then they will ask most of the time about it.
JAX-RS is nothing but a Java programming language API. It is similar to JDK library API. But, here we need to externally
add in our path. We will setup further in session. Like How to download JAX-RS and How to make
simple example.
JAX-RS API is designed to make it easy
to develop applications. Since, JAX-RS API uses the REST architecture.
The JAX-RS API
uses annotations of Java programming language. So that the development of
RESTful web services become very simple rather than other. Application developers and software engineers
use to decorate java class files with these annotations, so that resources can
be defined and the actions that can be made on those resources.
Since, JAX-RS annotations are runtime annotations. Therefore,
runtime image will generate the helper classes and artifacts for the resource.
The Developed Java EE Application with JAX-RS resource classes will have the
resources configured, the helper classes and artifacts generated, and the
resource visible to clients by deploying the archive to a Java EE server.
As recommendation, there is simple example. For further learning in session and best understanding please go through this example.
http://www.techieuncle.com/2018/01/developing-restful-web-services-with.html
Annotations are defined by JAX-RS:
@Path Annotation:
The @Path annotation’s value is just like a family member URI path. It means that there Java class will be presented: for example, /saveUser. You can also insert variables in the URIs to make a URI path template. For example, you could ask for the name of a user and pass it to the application as a variable in the URI: //saveUser/{username}.
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("saveUser")
public class UserController
{
@GET
@Produces(MediaType.TEXT_PLAIN)
public String User()
{…}
}
In
the above recommended example, @Path("saveUser") indicating
that UserController class have information about exact path
that is Uri. Thus, registered User details will be fetched.http://localhost:8080/Dream/rest/saveUser