Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mike10004/nanohttpd-champion

Tools to use NanoHTTPD like a champ.
https://github.com/mike10004/nanohttpd-champion

Last synced: 10 days ago
JSON representation

Tools to use NanoHTTPD like a champ.

Awesome Lists containing this project

README

        

[![Travis build status](https://travis-ci.org/mike10004/nanohttpd-champion.svg?branch=master)](https://travis-ci.org/mike10004/nanohttpd-champion)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/gh1tuv64urbhfldb?svg=true)](https://ci.appveyor.com/project/mike10004/nanohttpd-champion)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.mike10004/nanohttpd-champion.svg)](https://repo1.maven.org/maven2/com/github/mike10004/nanohttpd-champion/)

# nanohttpd-champion

Use [NanoHTTPD](https://github.com/NanoHttpd/nanohttpd) like a champion.

## Maven


com.github.mike10004
nanohttpd-server
0.14

## Usage

import java.io.InputStream;
import java.nio.charset.Charset;
import io.github.mike10004.nanochamp.server.NanoControl;
import io.github.mike10004.nanochamp.server.NanoResponse;
import io.github.mike10004.nanochamp.server.NanoServer;

public class NanoServerExample {

public static void main(String[] args) throws Exception {
Charset charset = Charset.forName("UTF-8");
NanoServer server = NanoServer.builder()
.get(request -> NanoResponse.status(200).plainText("hello, world", charset))
.build();
try (NanoControl control = server.startServer();
InputStream in = control.baseUri().toURL().openStream()) {
byte[] buffer = new byte[1024];
int r = in.read(buffer);
String content = new String(buffer, 0, r, charset);
System.out.println(content); // hello, world
}
}
}