- supported: jackson, gson
<repositories>
<repository>
<id>pne</id>
<name>payneteasy repo</name>
<url>https://maven.pne.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.payneteasy</groupId>
<artifactId>api-servlet</artifactId>
<version>1.0-5</version>
</dependency>
compile 'com.payneteasy:api-servlet:1.0-5'
Create a service class
public class HelloServiceSample {
public ResponseMessageSample sayHello(RequestMessageSample aName) {
ResponseMessageSample response = new ResponseMessageSample();
response.text = "Hello " + aName.name;
return response;
}
}
Server jetty = new Server(8080);
ServletContextHandler context = new ServletContextHandler(jetty, "/api", ServletContextHandler.NO_SESSIONS);
ObjectMapper mapper = new ObjectMapper();
HelloServiceSample service = new HelloServiceSample();
context.addServlet(new ServletHolder(new JacksonApiServlet<>(service::sayHello, RequestMessageSample.class, ResponseMessageSample.class, mapper)), "/user/*");
Server jetty = new Server(8080);
ServletContextHandler context = new ServletContextHandler(jetty, "/api", ServletContextHandler.NO_SESSIONS);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
GsonJettyContextHandler handler = new GsonJettyContextHandler(context, gson);
HelloServiceSample service = new HelloServiceSample();
handler.addApi("/user/*", service::sayHello, RequestMessageSample.class);
The ApiServlet library is licensed under the Apache License 2.0