Skip to content

Resolving URIs to handlers #2558

@sazzer

Description

@sazzer

Hi there,

The existence of HttpRequest::url_for is fantastic for building real REST APIs. I can use this to generate URIs for other resources so that I can correctly generate the hypermedia graph.

However, what I can't quite work out how to do is the opposite. To take a URL that was was provided to me and convert it back into the details of what it resolves to.

If I understand it right, I can use HttpRequest::resource_map().match_name() to get the name of the handler that matches a given URL, but this doesn't give me the binds.

For example, if I had:

    config.service(
        web::resource("/users/{id}")
            .name("users_user_by_id")
            .route(web::get().to(get::handler)),
    );

Then I could use req.resource_map().match_name("http://localhost:8000/users/abc") to get Some("users_user_by_id"), but that would not tell me that the {id} bind was assigned the value "abc".

Is there any way to get this full expansion?

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions