Riposte
Riposte is a Netty-based microservice framework for rapid development of production-ready HTTP APIs.
Install / Use
/learn @Nike-Inc/RiposteREADME
Riposte
[![Maven Central][maven_central_img]][maven_central] [![Build][gh_action_build_img]][gh_action_build] [![Code Coverage][codecov_img]][codecov] [![License][license img]][license]
Riposte is a Netty-based microservice framework for rapid development of production-ready HTTP APIs. It includes robust features baked in like distributed tracing (provided by the Zipkin-compatible Wingtips), error handling and validation (pluggable implementation with the default provided by Backstopper), and circuit breaking (provided by Fastbreak). It works equally well as a fully-featured microservice by itself (see the template microservice project), or as an embedded HTTP server inside another application.
Quickstart
Java 8 is required.
Please see the template microservice project for the recommended starter template project AND usage documentation. The template project is a production-ready microservice with a number of bells and whistles and the template project's README.md contains in-depth usage information and should be consulted first when learning how to use Riposte.
That said, the following class is a simple Java application containing a fully-functioning Riposte server. It represents the minimal code necessary to run a Riposte server. You can hit this server by calling http://localhost:8080/hello and it will respond with a text/plain payload of Hello, world!.
public class MyAppMain {
public static void main(String[] args) throws Exception {
Server server = new Server(new AppServerConfig());
server.startup();
}
public static class AppServerConfig implements ServerConfig {
private final Collection<Endpoint<?>> endpoints = Collections.singleton(new HelloWorldEndpoint());
@Override
public Collection<Endpoint<?>> appEndpoints() {
return endpoints;
}
}
public static class HelloWorldEndpoint extends StandardEndpoint<Void, String> {
@Override
public Matcher requestMatcher() {
return Matcher.match("/hello");
}
@Override
public CompletableFuture<ResponseInfo<String>> execute(RequestInfo<Void> request,
Executor longRunningTaskExecutor,
ChannelHandlerContext ctx) {
return CompletableFuture.completedFuture(
ResponseInfo.newBuilder("Hello, world!")
.withDesiredContentWriterMimeType("text/plain")
.build()
);
}
}
}
The Hello World Sample is similar to this but contains a few more niceties, and that sample's README.md includes information on some of the features you can expect from Riposte, but again, please see the template microservice project for the recommended starter template project and usage documentation.
Riposte usage with other JVM-based languages
Since Riposte is straight Java 8 with no bytecode manipulation, plugins, or other magic required it works seamlessly with whatever JVM language you prefer. Here's the same hello world app from above, but this time in Kotlin:
fun main(args : Array<String>) {
val server = Server(AppServerConfig)
server.startup()
}
object AppServerConfig : ServerConfig {
private val endpoints = Collections.singleton(HelloWorldEndpoint)
override fun appEndpoints(): Collection<Endpoint<*>> {
return endpoints
}
}
object HelloWorldEndpoint : StandardEndpoint<Void, String>() {
override fun requestMatcher(): Matcher {
return Matcher.match("/hello")
}
override fun execute(request: RequestInfo<Void>,
longRunningTaskExecutor: Executor,
ctx: ChannelHandlerContext
): CompletableFuture<ResponseInfo<String>> {
return CompletableFuture.completedFuture(
ResponseInfo.newBuilder("Hello, world!")
.withDesiredContentWriterMimeType("text/plain")
.build()
)
}
}
And again in Scala:
object Main extends App {
val server = new Server(AppServerConfig)
server.startup()
}
object AppServerConfig extends ServerConfig {
val endpoints: java.util.Collection[Endpoint[_]] = java.util.Collections.singleton(HelloWorldEndpoint)
override def appEndpoints(): java.util.Collection[Endpoint[_]] = endpoints
}
object HelloWorldEndpoint extends StandardEndpoint[Void, String] {
override def requestMatcher(): Matcher = Matcher.`match`("/hello")
override def execute(
request: RequestInfo[Void],
longRunningTaskExecutor: Executor,
ctx: ChannelHandlerContext): CompletableFuture[ResponseInfo[String]] =
{
CompletableFuture.completedFuture(
ResponseInfo.newBuilder("Hello, world!")
.withDesiredContentWriterMimeType("text/plain")
.build()
)
}
}
Template Microservice Project
It's been mentioned already, but it bears repeating: Please see the template microservice project for the recommended starter template project AND usage documentation. The template project is a production-ready microservice with a number of bells and whistles and the template project's README.md contains in-depth usage information and should be consulted first when learning how to use Riposte. The rest of the documentation below in this readme will be focused on the Riposte core libraries.
Riposte Libraries
Riposte is a collection of several libraries, mainly divided up based on dependencies. Note that only riposte-spi and riposte-core are required for a functioning Riposte server. Everything else is optional, but potentially useful depending on the needs of your application:
- riposte-spi - Contains the main interfaces and classes necessary to define the interface for a Riposte server.
- riposte-core - Builds on
riposte-spito provide a fully functioning Riposte server. - riposte-async-http-client2 - Contains
AsyncHttpClientHelper, an HTTP client for performing async nonblocking calls usingCompletableFutures with distributed tracing baked in. This is a wrapper around the Async Http Client libraries. - riposte-async-http-client - DEPRECATED - Please use riposte-async-http-client2.
The older version of
AsyncHttpClientHelper, built around the Ning AsyncHttpClient (which eventually became the new Async Http Client project whichriposte-async-http-client2is based on). - riposte-metrics-codahale - Contains metrics support for Riposte using the
io.dropwizardversion of Codahale metrics. - riposte-metrics-codahale-signalfx - Contains SignalFx-specific extensions of the
riposte-metrics-codahalelibrary module. - riposte-auth - Contains a few implementations of the Riposte
RequestSecurityValidator, e.g. for basic auth and other security schemes. - riposte-guice - Contains helper classes for seamlessly integrating Riposte with Google Guice.
- riposte-typesafe-config - Contains helper classes for seamlessly integrating Riposte with Typesafe Config for properties management.
- riposte-guice-typesafe-config - Contains helper classes that require both Google Guice and Typesafe Config.
- riposte-archaius - Contains Riposte-related classes that require the Netflix Archaius dependency for properties management.
- riposte-service-registration-eureka - Contains helper classes for easily integrating Riposte with Netflix's Eureka service registration system.
- riposte-servlet-api-adapter - Contains
HttpServletRequestandHttpServletResponseadapters for reusing Servlet-based utilities in Riposte.
These libraries are all deployed to Maven Central and can be pulled into your project by referencing the relevant dependency: com.nike.riposte:[riposte-lib-artifact-name]:[version].
Full Core Libraries Documentation
Full documentation on the Riposte libraries will be coming eventually. In the meantime the javadocs for Riposte classes are fairly fleshed out and give good guidance, and the template microservice project is a reasonable user guide. Here are some important classes to get you started:
com.nike.riposte.server.Server- The Riposte server class. Binds to a port and listens for incoming HTTP requests. Uses [ServerConfig](https://github.com/Nike-Inc/riposte
