Specification
JAX-RS is a specification for implementing REST web services using the Java EE technologies.
Implementations
- Jersey
- RESTEasy
- Apache CXF
Example using the JAX-RS API:
@Path("/justsayhello")
public class YourOwnJaxRsController {
@GET
@Path("/{name}")
@Produces(MediaType.TEXT_PLAIN)
public Response justSayHello(@PathParam("name") String name) {
String greeting = "Just saying Hello " + name;
return Response.ok(greeting).build();
}
}
Alternative
Spring MVC
The equivalent implementation using the Spring MVC would be:
@RestController
@RequestMapping("/justsayhello")
public class YourOwnSpringRestController {
@RequestMapping(method = RequestMethod.GET,
value = "/{name}",
produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<?> justSayHello(@PathVariable String name) {
String greeting = "Just saying Hello " + name;
return new ResponseEntity<>(greeting, HttpStatus.OK);
}
}
Using Spring Boot and Jersey
Use the spring-boot-starter-jersey module to develop REST endpoints using JAX-RS instead of Spring MVC.