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


public class ServerClientTest {

    private HttpServer server;
    private WebTarget target;

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

        Client c = ClientBuilder.newClient();
        target =;

    public void tearDown() throws Exception {

     * Test to see that the message "Got it!" is sent in the response.
    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
Data Science
Linear Algebra Mathematics

Powered by ComboStrap