module util::Webserver
rascal-0.40.16
Usage
import util::Webserver;
Dependencies
extend Content;
function serve
void serve(loc server, Response (Request) callback, bool asDaemon = true)
function shutdown
void shutdown(loc server)
Tests
test testWebServer
test bool testWebServer() {
loc testLoc = |http://localhost:10001|;
// simple get
// Response testServer(get("/hello")) = response("hello world!");
Response testServer(p:post("/upload8", value (type[value] _) stuff)) = response("uploaded: <p.parameters["firstname"]> <stuff(#value)>");
try {
serve(testLoc, testServer);
return true;
}
catch value exception:
throw exception;
finally {
shutdown(testLoc);
}
}