Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit routing without invoking actions #155

Open
jjl opened this issue Mar 14, 2019 · 4 comments
Open

Permit routing without invoking actions #155

jjl opened this issue Mar 14, 2019 · 4 comments

Comments

@jjl
Copy link

jjl commented Mar 14, 2019

I didn't see anything in the router blog post, but one of the commonly requested features in other web frameworks across various languages is to be able to use the router without invoking code.

For example, given a route /foo/:bar and a path /foo/quux, one would ideally be able to obtain some sort of identifier for the route and the mapping bar -> quux.

One initial problem would seem to be that there is no natural identifier for the route.

@yoshuawuyts
Copy link
Member

@jjl does #24 cover the topics you're talking about here?

@jjl
Copy link
Author

jjl commented Mar 19, 2019

Named routes would solve the having an identifier for the route, but it doesn't address the rest of the request.

@aturon
Copy link
Collaborator

aturon commented Apr 10, 2019

Could you say more about the use-case here? It wouldn't be hard to do routing without invoking any code, but it's not quite clear to me what the end goal is.

@Gowee
Copy link

Gowee commented May 27, 2019

I think @jjl are looking forward to features similar to extractors in actix-web, where desired params are automatically passed to the endpoint function without the needs to be extracted manually from cx.

An example from the actix-web docs:

use actix_web::{App, Path, Result, http};

/// extract path info from "/users/{userid}/{friend}" url
/// {userid} -  - deserializes to a u32
/// {friend} - deserializes to a String
fn index(info: Path<(u32, String)>) -> Result<String> {
    Ok(format!("Welcome {}! {}", info.1, info.0))
}

fn main() {
    let app = App::new().resource(
        "/users/{userid}/{friend}",                    // <- define path parameters
        |r| r.method(http::Method::GET).with(index));  // <- use `with` extractor
}

. It is not necessary at all as a matter of capabilities. But it does help reduce a lot of boilerplate codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants