Java - Rest

1 - About

3 - Specification

  • Jax Rs is an annotated Rest specification

4 - Implementation

  • jersey is the most well known implementation

5 - 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);
    }
}

5.1 - Javdoc

See Javadoc for JaxRs

5.2 - Framework


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap