Which of the following annotation of JAX RS API is used to annotate a ...
Answer: C
Explanation: @PUT – HTTP Get request, used to create resource.
View all questions of this test
Which of the following annotation of JAX RS API is used to annotate a ...
Understanding JAX-RS Annotations
JAX-RS (Java API for RESTful Web Services) is a set of APIs to create web services in Java. It utilizes annotations to define how requests and resources are handled.
Method for Creating Resources
In RESTful services, different HTTP methods correspond to different operations:
- @GET: Used to retrieve data from a server.
- @PUT: Typically used to update or replace an existing resource.
- @POST: Specifically designed to create a new resource on the server.
Why @POST is the Correct Choice
The annotation used to create a resource is @POST:
- Purpose: It signifies that a client is requesting the server to create a new resource, often submitting data in the request body.
- Usage: When the client sends a POST request, the server processes the data and usually creates a new instance of a resource. For example, submitting a new user registration.
- Response: The server usually returns a status code indicating success (e.g., 201 Created) along with a location header pointing to the newly created resource.
Conclusion
Thus, option 'C' (@POST) is the correct answer for annotating a method that creates a resource in a JAX-RS application, as it aligns with the RESTful principles of resource management.