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

Allow optional path segments #1054

Closed
vmalloc opened this issue Aug 25, 2019 · 7 comments
Closed

Allow optional path segments #1054

vmalloc opened this issue Aug 25, 2019 · 7 comments

Comments

@vmalloc
Copy link
Contributor

vmalloc commented Aug 25, 2019

I was wondering how to implement a query for either a collection or a subresource, using the same handler. For example, say we have /products and /products/{product_id} -- it is currently impossible to manage both in the same handler conveniently.

I was wondering if it could be possible to use web::Path<Option<String>> for such cases, and have the handler check if a product id was specified in the URL. If that sounds reasonable I can try and craft a PR for it.

@jesskfullwood
Copy link
Contributor

jesskfullwood commented Aug 25, 2019

Interesting idea. How would we handle the case of /some_path/{some_id}/more/paths?

@vmalloc
Copy link
Contributor Author

vmalloc commented Aug 25, 2019

I think the optional scenario would only match in case the last path segment is both a parameter and missing...

@fafhrd91
Copy link
Member

fafhrd91 commented Dec 25, 2019

It is possible to use multiple patterns for resource in 2.0

App::new().service(web::resource([‘path1’, ‘path2/{name}/‘]).to(...)

@ChriFo
Copy link

ChriFo commented Jan 10, 2020

Which method signature is needed for a resource with multiple patterns and optional path segment?

@vmalloc
Copy link
Contributor Author

vmalloc commented Jan 11, 2020

@ChriFo i don’t think this is supported with extractors. You would need to pass HttpRequest and use match_info to distinguish between the cases

@s97712
Copy link

s97712 commented Jul 19, 2020

It is possible to use multiple patterns for resource in 2.0

App::new().service(web::resource([‘path1’, ‘path2/{name}/‘]).to(...)

How to do for actix_web::get/actix_web::post?

@robjtede
Copy link
Member

robjtede commented Jul 19, 2020

How to do for actix_web::get/actix_web::post?

@s97712 Currently, it's not possible to provide multiple paths using the macros. PRs welcome.

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

6 participants