expose Method in tide mod
Currently in order to use Method I need to import use tide::http::Method while for status code I can simply write use tide::StatusCode.
Imports are looking like
use tide::{http::Method, Request, Response, StatusCode};
Would it be possible to also expose Method as tide::Method to align with rest of the apis? Not sure if it was deliberate.
I think it was suspected that perhaps Method would not be so commonly used in Tide as opposed to Surf?
That does make sense. @prabirshrestha when do you find yourself using Method in a tide app? That also might indicate somewhere the api could be better
This is usefull when using .all().
app.at("/webdav/").all(handle_webdav);
async fn handle_webdav(req: Request<()>) -> tide::Result {
match req.method() => {
Method.OPTIONS => {},
Method.GET => {},
_ => {}
};
...
}
Why wouldn't you use the router in that circumstance?
I actually want to ship a webdav handler as a library that others can easily consume it as below.
async fn handle_webdav(req: Request<State>) -> tide::Result {
let webdav = WebdavHandler::new(vfs);
Ok(webdav.handle(&req).await?)
}
I had originally started with Webdav middleware but faced similar issue.
app.with(WebdavMiddleware::new(vfs));
app.at("*").all(|| async { Ok(Response::new(StatusCode::NotFound)) };
Either way I still need to match on Method.
Why not ship a tide Server that can be nested? Regardless, this seems like very rare usage that probably doesn't require making Method easier to access
I did experiment with it but hit the trailing slash issue. https://github.com/http-rs/tide/issues/205#issuecomment-841729547. Though this is a minor issue that I could wait and update when fixed.
As mentioned in https://github.com/http-rs/tide/issues/830, I'm hoping to have a generic handler that takes Request and returns Result<Response> from http_types so trying to avoid tide specific code if possible. Then it might not matter since now will be use Method from http_types instead.
Are there other server frameworks that use http_types that you're hoping to support?
I'm not aware of any but just experimenting with ideas.
Ideally one could write Request -> Result<Response> fn and make it work in other frameworks. Then might be one could just have to_actix_middleware(webdav_handler) or to_tide_middleware(webdav_handler)
If you're trying to avoid tide types, wouldn't you just directly depend on http_types::Method?
Yes I would in this case. But did find it weird that I had to use tide::http_types::Method. In other cases where I don't want to convert all to http_types I was hoping to just use tide::Method as it felt more natural.
This was just a minor api difference I saw so not a major issue for me.