handy-httpd 1.4.0
Extremely lightweight HTTP server for D.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
handy-httpd
An extremely lightweight HTTP server for the D programming language. Handy-httpd uses a simple worker pool to process incoming requests, in conjunction with a user-defined HttpRequestHandler
. Consider the following example in which we serve files from the ./static/
directory:
import handy_httpd;
import handy_httpd.handlers.file_resolving_handler;
void main() {
auto s = new HttpServer(new FileResolvingHandler("static"));
s.start();
}
It's also quite simple to define your own custom request handler. Here's an example of a custom request handler that only responds to the /hello
endpoint:
import handy_httpd;
void main() {
auto s = new HttpServer(simpleHandler((request) {
if (request.url == "/hello") {
return okResponse()
.setBody("Hello world!");
} else {
return notFound();
}
}));
s.start();
}
Note: the
HttpRequestHandler simpleHandler(HttpResponse function(HttpRequest) fn)
function allows you to pass a function as a request handler. Internally, it's using an anonymous class.
For more information, please check out the wiki on GitHub.
- 1.4.0 released 2 years ago
- andrewlalis/handy-httpd
- MIT
- Copyright © 2021, Andrew Lalis
- Authors:
- Dependencies:
- httparsed
- Versions:
-
8.4.2 2024-Sep-27 8.4.1 2024-Aug-02 8.4.0 2024-Apr-16 8.3.2 2024-Feb-16 8.3.1 2024-Feb-14 - Download Stats:
-
-
0 downloads today
-
12 downloads this week
-
83 downloads this month
-
19594 downloads total
-
- Score:
- 3.6
- Short URL:
- handy-httpd.dub.pm