Java - Rest

Java Conceptuel Diagram

About

Web Service - Representational State Transfer (REST|RESTful) Web services in Java

Specification

  • Jax Rs is an annotated Rest specification

Implementation

Test

When testing a Rest API (ie when writing a unit test), there is two approach:

  • you create a context object to emulate an incoming request
  • or you start an embedded server and use a client to make http request

Example:

public class ServerClientTest {

    private HttpServer server;
    private WebTarget target;

    @Before
    public void setUp() throws Exception {
        server = Main.startServer();

        Client c = ClientBuilder.newClient();
        target = c.target(Main.BASE_URI);
    }

    @After
    public void tearDown() throws Exception {
        server.stop();
    }

    /**
     * Test to see that the message "Got it!" is sent in the response.
     */
    @Test
    public void testGetIt() {
        String responseMsg = target.path("myresource").request().get(String.class);
        assertEquals("Got it!", responseMsg);
    }
}

Javdoc

See Javadoc for JaxRs

Framework





Discover More
Java Conceptuel Diagram
Java - API for RESTful Web Services (JAX-RS)

is a rest specification. The most known implementation is jaxDoclet...
Java Conceptuel Diagram
Java - Jersey (Rest Framework)

Eclipse Jersey is a REST framework that provides a JAX-RS (JSR-370) implementation and more Java Jersey redirects to
Java Conceptuel Diagram
RESTEasy

is a JBoss project that provides various frameworks to help you build RESTful Web Services and RESTful Java applications. It is a fully certified and portable implementation of the JAX-RS 2.0 specification,...
Java Conceptuel Diagram
Vert.x - Rest / Jax-RS

with vertx Many wrapper libraries (Rest, CDI, ...) use a thread-local context so that the user-code method can look them up when executed. In the case of RESTEasy, the context holds this information:...
Web Service - Representational State Transfer (REST|RESTful) Web services

Representational State Transfer (REST) Web services, or “RESTful” Web services describes any simple interface that transmits data over a standardized interface (such as HTTP) without an additional...



Share this page:
Follow us:
Task Runner