miniweb 0.2.0

A minimal yet complete web framework


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:


This package provides sub packages which can be used individually:

miniweb:http - A full HTTP parser, supporting HTTP/1.x

Miniweb

A minimal yet complete webframework.

License

The code in this repository is licensed under AGPL-3.0-or-later; for more details see the LICENSE file in the repository.

Getting started

This library aims to have an small but complete webframework for dlang projects.

A simple hello world project:

module test;

import miniweb;
import miniweb.main;
mixin MiniWebMain!test;

@OnServerStart
void configureServer(ServerConfig conf) {
    conf.setCustomServerInfo("My Fancy Server");
}

@Route("/doSomething")
void doSomething() {
    writeln("Does something!");
}

@GET @Route("/returnSomething")
Response returnSomething(HeaderBag headers) {
    auto resp = Response.build_200_OK();
    resp.headers.set("X-My-Header", headers.get("X-My-Header"));
    resp.setBody("Hello world!");
    return resp;
}

Miniweb has the ability to analyse annotated functions and call them with any order of parameters, as long as minweb supports the type.

Currently supported are:

  • Request get the raw request
  • HeaderBag get the headers of the request
  • URI get the uri of the request
  • QueryParamBag get the query params of the request
  • HttpMethod get the requests HTTP method of the request

To use middlewares you have two options, either create a named one or use functionals:

@RegisterMiddleware("my_middleware")    // registers a named middleware
MaybeResponse handler(Request req) {
    return MaybeResponse.none();    // returns a Option!Response with no value set,
                                    // which effectivly means to call either the next middleware
                                    // or the handler.
}

// Middlewares can either return MaybeResponse or void and have
// the same freedom in their parameters as normal route handlers
@RegisterMiddleware("other")
void otherHandler() {}

@Route("/returnSomething")
@Middleware("my_middleware")    // applies a named middleware
Response returnSomething(HeaderBag headers) {
    // ...
}

@Route("/someWhereOther")
// This is a functional middleware, it accepts a delegate/function directly
@Middleware((req) {
    return MaybeReponse.none();
})
Response someWhereOther() {
    // ...
}

Roadmap

  • More bodytypes to move data
  • Allowing more returntypes, i.e. auto-serializing
  • Allowing detection of more request parameters
  • Routes with placeholders / regex
  • Full http/1.1 support
  • http/2 support
  • ssl/tls support
  • ...
Authors:
  • Mai-Lapyst
Sub packages:
miniweb:test, miniweb:http
Dependencies:
miniweb:http, miniasync
Versions:
1.0.1 2023-Jul-09
1.0.0 2023-Jul-03
0.4.0 2023-Jun-08
0.3.0 2023-Apr-09
0.2.0 2023-Apr-09
Show all 7 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 29 downloads total

Score:
0.4
Short URL:
miniweb.dub.pm