tide icon indicating copy to clipboard operation
tide copied to clipboard

make Request::rest public outside of the crate

Open jbr opened this issue 4 years ago • 5 comments

closes #426

jbr avatar Apr 20 '20 18:04 jbr

You can use app.all to match everything:

app.at("*").all(endpoint);

Is there still something missing?

yoshuawuyts avatar Apr 20 '20 18:04 yoshuawuyts

This is a different concern. Sorry I was unclear. Within a route handler with a "/nested/*" route, how do I get access to the entirety of the globbed part? (Not the request.uri(), just the unnamed * "param")

jbr avatar Apr 20 '20 19:04 jbr

Haven't quite understood your problem, but maybe you're aiming for /nested/*path which will give you the rest of the request path under /nested/ in a path param. You can then get it as any other param with req.param("path")....

use tide::Request;
use async_std::task;

fn main() {
    let mut app = tide::new();
    app.at("/nested/*path").get(|req: Request<()>| async move {
        let path: String = req.param("path").unwrap();
        println!("{}", path);
        path
    });

    task::block_on(app.listen("127.0.0.1:18888")).unwrap();
}

Worked with this request: curl -vvv 'localhost:18888/nested//ds/da((*&^/ds'

And the response is: /ds/da((*&^/ds

vladan avatar Apr 21 '20 13:04 vladan

As I mentioned in the issue, the param parser supports unnamed star globs, and they’re also mentioned in the tide docs, and as far as I can tell, tide stores them and has a method that is unused within the crate which does exactly this, but is pub(crate).

jbr avatar Apr 21 '20 16:04 jbr

Perhaps the solution is just to remove mention of unnamed globs from the docs, also the rest method and --tide-path-rest. It seems quite reasonable not to support them

jbr avatar Apr 21 '20 16:04 jbr