hunt-http
Hunt-Http is a flexible performant http server and client written in D Programming Language.
Simple codes
Using hunt-http build a web server
import hunt.http;
void main()
{
auto server = HttpServer.builder()
.setListener(8080, "0.0.0.0")
.setHandler((RoutingContext context) {
context.write("Hello World!");
context.end();
}).build();
server.start();
}
Using hunt-http build a http client
import hunt.http;
import std.stdio;
void main()
{
auto client = new HttpClient();
auto request = new RequestBuilder().url("http://www.huntlabs.net").build();
auto response = client.newCall(request).execute();
if (response !is null)
{
writeln(response.getBody().asString());
}
}
Using hunt-http build a websocket server
import hunt.http;
void main()
{
auto server = HttpServer.builder()
.setListener(8080, "0.0.0.0")
.websocket("/ws", new class AbstractWebSocketMessageHandler {
override void onText(WebSocketConnection connection, string text)
{
connection.sendText("Hello " ~ text);
}
}).build()
server.start();
}
Avaliable versions
Name | Description |
---|---|
HUNT_HTTP_DEBUG | Used to log debug messages about Hunt-HTTP |
HUNT_METRIC | Used to enable some operations and APIs about metric |
TODO
- [ ] Reorganizing modules
- [ ] PersistentCookieStore for HttpClient
- [ ] Benchmark
References
- Eclipse Jetty 9.4.x, https://github.com/eclipse/jetty.project