Java Academy Logo

Java Academy

JAX-RS — Java API for RESTful Web Services

JAX-RS is the standard Java specification for building RESTful web services. Implementations include Jersey (reference) and RESTEasy, commonly used in Jakarta EE applications.

JAX-RS Annotations

@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
public class UserResource {
    @GET
    @Path("/{id}")
    public Response getUser(@PathParam("id") Long id) {
        User user = userService.find(id);
        return Response.ok(user).build();
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public Response create(User user) {
        User saved = userService.save(user);
        return Response.status(201).entity(saved).build();
    }
}

JAX-RS vs Spring MVC

  • JAX-RS — Jakarta EE standard, portable across app servers (WildFly, GlassFish).
  • Spring MVC — Spring ecosystem, more popular for new projects and startups.
  • Both support REST; Spring Boot is the dominant choice in US/UK/AU job markets.
  • Learn JAX-RS for enterprise Jakarta EE maintenance roles.

Frequently Asked Questions

Is JAX-RS still relevant?

Yes in enterprise Jakarta EE environments. For new projects, Spring Boot REST is more common, but JAX-RS knowledge transfers well.

Continue Learning