api-servlet 1.0-3

Simple API servlet

License

License

Categories

Categories

Net
GroupId

GroupId

com.payneteasy
ArtifactId

ArtifactId

api-servlet
Last Version

Last Version

1.0-3
Release Date

Release Date

Type

Type

jar
Description

Description

api-servlet 1.0-3
Simple API servlet
Project URL

Project URL

https://github.com/payneteasy/api-servlet
Source Code Management

Source Code Management

https://github.com/payneteasy/api-servlet

Download api-servlet

How to add to project

<!-- https://jarcasting.com/artifacts/com.payneteasy/api-servlet/ -->
<dependency>
    <groupId>com.payneteasy</groupId>
    <artifactId>api-servlet</artifactId>
    <version>1.0-3</version>
</dependency>
// https://jarcasting.com/artifacts/com.payneteasy/api-servlet/
implementation 'com.payneteasy:api-servlet:1.0-3'
// https://jarcasting.com/artifacts/com.payneteasy/api-servlet/
implementation ("com.payneteasy:api-servlet:1.0-3")
'com.payneteasy:api-servlet:jar:1.0-3'
<dependency org="com.payneteasy" name="api-servlet" rev="1.0-3">
  <artifact name="api-servlet" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.payneteasy', module='api-servlet', version='1.0-3')
)
libraryDependencies += "com.payneteasy" % "api-servlet" % "1.0-3"
[com.payneteasy/api-servlet "1.0-3"]

Dependencies

provided (6)

Group / Artifact Type Version
org.slf4j : slf4j-api Optional jar 1.7.25
com.fasterxml.jackson.core : jackson-core Optional jar 2.9.9
com.fasterxml.jackson.core : jackson-databind Optional jar 2.9.10.1
com.google.code.gson : gson jar 2.8.6
javax.servlet : javax.servlet-api Optional jar 3.1.0
org.eclipse.jetty : jetty-servlet Optional jar 9.4.24.v20191120

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-core jar 2.27.0
org.slf4j : slf4j-simple jar 1.7.26

Project Modules

There are no modules declared in this project.

Maven Central Github Actions Status CircleCI Quality Gate Status

Simple API Servlet for JSON

Features

  • supported: jackson, gson

Setup with dependency managers

Maven

<dependency>
  <groupId>com.payneteasy</groupId>
  <artifactId>api-servlet</artifactId>
  <version>1.0-3</version>
</dependency>

Gradle

compile 'com.payneteasy:api-servlet:1.0-3'

How to use

Create a service class

public class HelloServiceSample {

    public ResponseMessageSample sayHello(RequestMessageSample aName) {
        ResponseMessageSample response = new ResponseMessageSample();
        response.text = "Hello " + aName.name;
        return response;
    }
}

Create servlet mapping with Jackson

    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/*");

Create with Gson

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

License

The ApiServlet library is licensed under the Apache License 2.0

com.payneteasy

Payneteasy

Payment Platform Provider

Versions

Version
1.0-3
1.0-2
1.0-1