🚀 Announcing Serverino 0.6.0! 🎉

Andrea Fontana nospam at example.com
Sun Mar 10 21:17:42 UTC 2024


Thank you! Inline replies >>>

On Sunday, 10 March 2024 at 21:04:05 UTC, aberba wrote:

>     1) I'm not sure I like concat (~=)
>      style used on `Output output` and how it can determine the 
> order routes are invoked. I would expect that to be explicitly 
> defined by Dev using a catch-all route or else the sever 
> returns 404 by default. That's going to prevent the chances of 
> invoking the wrong route especially when it does something 
> important/dangerous/unexpected.

Serverino works with priorities, that's the order the handlers 
are called! You're checks on handlers can easily filter request.

>
>
> 2) instead of doing:
>
>     ```d
>     if (request.method != Request.Method.Get)
>     		output.status = 405;
>     ```
>
> to determine the request method, why not use a UDA similar to 
> `@route` ...like `@method(Request.Method.post)`? The use of UDA 
> is so much cleaner and easier to deal with.
>

This works as well, indeed:
@route!(r => r.method == Request.Method.Post)

>
> 3) would be nice to have an `output.json()` function which both 
> sets the response header and also calls `output.write()`

Just add content type and you're done!

> 4. I can't build anything significant in any http server 
> library without support for middleware. Preferably support for 
> multiple middlewares functions. A middleware would be a 
> function that runs after the @onServerInit but BEFORE any route 
> handler. It will be used to intercept all incoming requests for 
> things like authentication, rate limiting, CORS, etc. 
> Preferably provide a way to pass data to the target route e.g. 
> user session, user permission, etc...like 
> output.locals.set("userId", 123). The route will then be able 
> to access this data.

Just use a high priority handler, check the tips on website, for 
example user auth.

That's a very clean way to add a layer of Auth, logging and so 
on...


> All in all, everything else looks good. I would prefer 
> something like:
>
>     ```d
>     void hello (Request req, Response res) {
>         res.write("hello");
>     }
>     ```
>     ...but `Output` is also fine... just a small nitpick.

output.write() works as well.

Andrea



More information about the Digitalmars-d-announce mailing list