About
Web Service - Representational State Transfer (REST|RESTful) Web services in Java
Articles Related
Specification
- Jax Rs is an annotated Rest specification
Implementation
- jersey is the most well known 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:
- Armeria https://line.github.io/armeria/advanced-unit-testing.html - where create a context object
- Jersey where you start you main server and make client call
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
Framework
- https://github.com/airlift/airlift - Airlift framework for building REST services - Airlift is a toolkit for building distributed services and it is the foundation of Presto. (sample-server)
- https://www.dropwizard.io/ - no direct support for distributed computing patterns
- Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation.