Archttp - Fast and easy to use web framework.
zoujiaqing
zoujiaqing at gmail.com
Sat May 14 14:58:52 UTC 2022
Hi, everybody.
The epidemic in China is serious. I am in home quarantine in
Shanghai.
I used to write a lot of frameworks. But they are huge and
difficult to use.
I've always wanted to design a lightweight Web framework that is
easy to use and has good performance. These days I finally write
a version. This version currently runs well on Linux and macOS.
We haven't had time to test it on Windows yet.
## Sample code:
```D
import archttp;
void main()
{
auto app = new Archttp;
app.Bind(8080);
app.Get("/", (context) {
auto response = context.response();
response.body("Hello Archttp");
});
app.Get("/json", (context) {
import std.json;
auto response = context.response();
auto j = JSONValue( ["message" : "Hello, World!"] );
response.json(j);
});
app.Get("/user/{id:\\d+}", (context) {
auto request = context.request();
auto response = context.response();
response.body("User id: " ~ request.parameters["id"]);
});
app.Get("/blog/{name}", (context) {
auto request = context.request();
auto response = context.response();
response.body("Username: " ~ request.parameters["name"]);
});
app.Post("/upload", (context) {
auto response = context.response();
response.body("Using post method!");
});
app.Run();
}
```
The project relies on 'nbuff' and 'httparsed', which provide very
powerful support for 'Archttp'.
** Thanks to 'ikod' and 'Tchaloupka'.**
Be aware that there will be many changes and tweaks to the API in
the future. It's not a stable version yet.
The current project supports HTTP 1.1 request processing. And a
good built-in routing module.
## Examples of running projects:
```bash
git clone https://github.com/kerisy/archttp.git
cd archttp/examples/httpserver/
dub run
```
## Project source code:
https://github.com/kerisy/archttp
More information about the Digitalmars-d-announce
mailing list