A 8.5kB Nashorn HTTP Server

nano is a zero-dependency, "convention over configuration" HTTP server entirely based on Java 8.

Nano is available as a self-contained: jar.

Put a file world.js:


function process(method, requestHeaders, responseHeaders, request, response) {
    response.write("Hello, world!");
    return 200;
}


into the folder hello and start nano with java -jar nano.jar . 4242

Output:


Context registered: /hello/world
nano started in: 441ms at port: 4242

Now curl -i http://localhost:4242/hello/world prints:


HTTP/1.1 200 OK
Date: Tue, 22 Dec 2015 04:28:59 GMT
Content-length: 13

Hello, world!%     

Interested in Micro, Nano, Pico Java EE? See you at Java EE Workshops at Munich Airport, Terminal 2 and particularly Microservices with Java 8 and Java EE 7. Is Munich's airport too far? Learn from home: airhacks.io.

Comments:

Nice, have a look also at spark: http://sparkjava.com/ :)

Posted by Marek on December 22, 2015 at 09:01 AM CET #

Still haven't looked into Nasven? :P

Posted by Bruno Borges on December 23, 2015 at 01:22 AM CET #

Where I use this Java code in my private blog?

Posted by server management on June 22, 2016 at 02:18 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License