3 ms·
I'm curious, in this example, what does MiddlewareResult::Next do? use feather::{App, AppContext, MiddlewareResult,Request, Response}; fn main() {
by refulgentis 2y ago
I'm curious, in this example, what does MiddlewareResult::Next do?
use feather::{App, AppContext, MiddlewareResult,Request,
Response};
fn main() {
let mut app = App::new();
app.get("/",|_req: &mut Request, res: &mut Response, _ctx: &mut AppContext| {
res.send_text("Hello, world!");
MiddlewareResult::Next
});
app.listen("127.0.0.1:3000");
}
Given my lack of experience, I'm sure it's needed, it's just unclear to me what purpose it would serve in a server app.
- IshKebab 2y agoWhy does it not look lightweight? I think you might be seeing "middleware" and thinking that it enables a load of middleware by default, which is unlikely to be the case?
- Qwuke 2y agoWhen you have 20 routes each being terminated with redundant `res.json(success);\n MiddleWare::Next` I think you can imagine why someone might see it as not lightweight in terms of unnecessary boilerplate - which most Rust webframeworks, async or not, don't require you to write out.
- refulgentis 2y ago^ This. I am mostly naive to Rust and web server frameworks, so its a naive thought that may be completely contraindicated due to other issues, but I don't expect to see meaningless(?)/repetitive code in the advertisement for a framework that advertises as lightweight.
- IshKebab 2y agoI don't think a simple enum return value really counts it out as lightweight.
- Qwuke 2y agoYou're right, it doesn't really seem necessary and makes the responses of the route end up as side effects rather than part of the return type of the route functions. Most web frameworks in Rust don't make responses a side effect and keep them as a response return type since that's better devex and much less boilerplate.