Skip to content

Instantly share code, notes, and snippets.

@ItGumby
Created December 21, 2017 18:54
Show Gist options
  • Save ItGumby/9a61dc493eb9ba2bd71f344e08ae3d36 to your computer and use it in GitHub Desktop.
Save ItGumby/9a61dc493eb9ba2bd71f344e08ae3d36 to your computer and use it in GitHub Desktop.
WebServer.groovy
#! /usr/bin/env groovy
import com.sun.net.httpserver.HttpServer
/**
* http://localhost:8080/hello
*/
HttpServer.create(new InetSocketAddress(8080), 0).with {
createContext("/hello") { http ->
http.responseHeaders.add("Content-type", "text/plain")
http.sendResponseHeaders(200, 0)
http.responseBody.withWriter { out ->
out << "Hello ${http.remoteAddress.hostName}!"
}
}
start()
}
@ItGumby
Copy link
Author

ItGumby commented Dec 21, 2017

from http://glaforge.appspot.com/article/the-jdk-built-in-web-server-with-apache-groovy

  • doesn't serve folder/content, but does start fast & show how to respond easily

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment