← Back to Feed
retoor
retoor · Level 54808
devlog

It goes extremely well with my native zero cost high level libraries implementation to the programming language. Imagine this, native;

Canonical usage example

aiohttp::Response hello_get(aiohttp::Request *req) {
    const char *id = aiohttp::Request_match_info(req, "id");
    (void)id;
    return aiohttp::Response_text("Hello from HelloView");
}

aiohttp::Response submit_put(aiohttp::Request *req) {
    printf("submit_view: received body=%s\n", aiohttp::Request_get_body(req));
    return aiohttp::Response_status(201, "Submitted");
}

aiohttp::Response delete_item(aiohttp::Request *req) {
    (void)req;
    return aiohttp::Response_status(204, "");
}

aiohttp::Application app = new aiohttp::Application();
app.add_get("/items/{id}", (void *)hello_get);
app.add_put("/items/{id}", (void *)submit_put);
app.add_delete("/items/{id}", (void *)delete_item);

aiohttp::Request req1 = new aiohttp::Request("GET", "/items/123");
aiohttp::Response res1 = await app.handle(&req1);
printf("app: GET /items/123 -> status=%d body=%s\n", res1.status, res1.body.data);

aiohttp::Request req2 = new aiohttp::Request("PUT", "/items/456");
req2.set_body("{\"name\":\"updated\"}");
aiohttp::Response res2 = await app.handle(&req2);
printf("app: PUT /items/456 -> status=%d body=%s\n", res2.status, res2.body.data);

printf("app: router lookup GET /items/{id} -> %s\n",
       app.lookup("GET", "/items/{id}") ? "found" : "miss");

aiohttp::HelloView hv = new aiohttp::HelloView();
aiohttp::Response vr = await hv.get();
printf("view.get: %s\n", vr.body.data);

req1.free();
req2.free();
res1.free();
res2.free();
vr.free();
hv.free();
app.free();

Application example

aiohttp::Application app = new aiohttp::Application();
app.add_get("/items/{id}", (void *)hello_get);

aiohttp::Request req = new aiohttp::Request("GET", "/items/123");
aiohttp::Response res = await app.handle(&req);
printf("status=%d body=%s\n", res.status, res.body.data);

req.free();
res.free();
app.free();

Serving real HTTP (plaintext)

asyncio::EventLoop loop = new asyncio::EventLoop();
aiohttp::Application app = new aiohttp::Application();
app.add_get("/live", (void *)live_get);

asyncio_Server *srv = await aiohttp::Application_listen(&app, &loop, "127.0.0.1", 8080, 64);
await asyncio::EventLoop_run(&loop);

Serving real HTTPS (TLS)

asyncio_TlsContext *server_ctx = asyncio::TlsContext_server("server.pem", "server-key.pem");
asyncio_Server *srv = await aiohttp::Application_listen_tls(&app, &loop, server_ctx, "0.0.0.0", 443, 64);

Request example

aiohttp::Request qreq = new aiohttp::Request("GET", "/search");
qreq.set_query("q", "aiohttp");
printf("query q=%s\n", qreq.query("q"));

qreq.free();

Response example

aiohttp::Response r = aiohttp::Response_text("logged in");
r.cookie("sid", "abc123");
printf("status=%d set-cookie=%s\n", r.status, r.set_cookie.data);

r.free();

View example

aiohttp::View v = new aiohttp::View();
aiohttp::Response r = await v.get();
printf("%s\n", r.body.data);

r.free();
v.free();

HelloView example

aiohttp::HelloView hv = new aiohttp::HelloView();
aiohttp::Response vr = await hv.get();
printf("view.get: %s\n", vr.body.data);

vr.free();
hv.free();

SubmitView example

aiohttp::SubmitView sv = new aiohttp::SubmitView();
aiohttp::Response r = await sv.put();
printf("status=%d body=%s\n", r.status, r.body.data);

r.free();
sv.free();

Router example

aiohttp::Router router = new aiohttp::Router();
router.add_get("/items/{id}", (void *)hello_get);

aiohttp::Request req = new aiohttp::Request("GET", "/items/123");
aiohttp::Response res = await router.dispatch(&req);
printf("status=%d\n", res.status);

req.free();
res.free();
router.free();

Route example

aiohttp::Router router = new aiohttp::Router();
router.add_get("/live", (void *)live_get);
printf("registered: %s\n", router.lookup("GET", "/live") ? "found" : "miss");

router.free();

Comments

retoor retoor

IT supports also class based views and stuff. I am thinking to implement an optional garbage colelctor. ALso, like the previous version, several async engines. THe differences are really interesting.

retoor retoor

I have to warn you, the docs are 2.6mb and this is only for users.

retoor retoor

|---|---|---|
| Overall GPA | 3.85 / 4.0 | Production Ready |
| Memory Safety | A+ | Perfect |
| Type Safety | A+ | Perfect |
| Documentation | A+ | Exceptional |
| Build System | A+ | Professional |
| Code Quality | A | Excellent |
| Testing | A | Comprehensive |
| Architecture | A+ | Elegant |
| Known Gaps | B | Documented, planned |
| Development Discipline | A+ | Excellent |
| API Design | A | Pythonic |

retoor retoor

My compiler pipeline is so good, so far i did not had any problem between different features