## NanoHTTPD – a tiny web server in Java *NanoHTTPD* is a light-weight HTTP server designed for embedding in other applications, released under a Modified BSD licence. It is being developed at Github and uses Apache Maven for builds & unit testing: * Build status: [![Build Status](https://api.travis-ci.org/NanoHttpd/nanohttpd.png)](https://travis-ci.org/NanoHttpd/nanohttpd) * Coverage Status: [![Coverage Status](https://coveralls.io/repos/NanoHttpd/nanohttpd/badge.svg)](https://coveralls.io/r/NanoHttpd/nanohttpd) * Current central released version: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.nanohttpd/nanohttpd/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.nanohttpd/nanohttpd) ## Quickstart We'll create a custom HTTP server project using Maven for build/dep system. This tutorial assumes you are using a Unix variant and a shell. First, install Maven and Java SDK if not already installed. Then run: mvn compile mvn exec:java -pl webserver -Dexec.mainClass="fi.iki.elonen.SimpleWebServer" You should now have a HTTP file server running on . ### Custom web app Let's raise the bar and build a custom web application next: mvn archetype:generate -DgroupId=com.example -DartifactId=myHellopApp -DinteractiveMode=false cd myHellopApp Edit `pom.xml`, and add this between \: org.nanohttpd nanohttpd 2.2.0 Edit `src/main/java/com/example/App.java` and replace it with: ```java package com.example; import java.util.Map; import java.io.IOException; import fi.iki.elonen.NanoHTTPD; public class App extends NanoHTTPD { public App() throws IOException { super(8080); start(); System.out.println( "\nRunning! Point your browers to http://localhost:8080/ \n" ); } public static void main(String[] args) { try { new App(); } catch( IOException ioe ) { System.err.println( "Couldn't start server:\n" + ioe ); } } @Override public Response serve(IHTTPSession session) { String msg = "Hello server\n"; Map parms = session.getParms(); if (parms.get("username") == null) { msg += "\n Your name: \n" + "\n"; } else { msg += "Hello, " + parms.get("username") + "!"; } return newFixedLengthResponse( msg + "
Your name:
Hello, " + parms.get("username") + "!