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

Support optional path parameters #95

Closed
6 tasks done
CathalMullan opened this issue Aug 13, 2024 · 0 comments · Fixed by #147
Closed
6 tasks done

Support optional path parameters #95

CathalMullan opened this issue Aug 13, 2024 · 0 comments · Fixed by #147

Comments

@CathalMullan
Copy link
Contributor

CathalMullan commented Aug 13, 2024

Optionals

Having ? at the end of a parameter name will mark it as optional.

Any characters that precede it will also be considered part of the same optional segment, excluding /.

This is less explicit than a 'grouping' syntax, but should be just as easy to understand.

Types

Dynamic Segment

/users/{id?}

Equivalent

  • /users
  • /users/{id}

Match

  • /users -> OK
  • /users/123 -> OK
  • /users/123/456 -> ERR

Wildcard Segment(s)

/files/{*path?}

Equivalent

  • /files
  • /files/{*path}

Match

  • /files -> OK
  • /files/report.pdf -> OK
  • /files/images/beach.jpg -> OK

Inline Dynamic Section

/users/{user}/profile.{ext?}

Equivalent

  • /users/{user}/profile
  • /users/{user}/profile.{ext}

Match

  • /users/{user} -> ERR
  • /users/{user}/profile -> OK
  • /users/{user}/profile. -> ERR
  • /users/{user}/profile.jpg -> OK
  • /users/{user}/profile.jpg.png -> OK, BUT WEIRD

Inline Dynamic Section(s)

/release/v{major}.{minor?}.{patch?}

Equivalent

  • /release/v{major}
  • /release/v{major}.{minor}
  • /release/v{major}.{minor}.{patch}

Match

  • /release/v4 -> OK
  • /release/v4. -> ERR
  • /release/v4.1 -> OK
  • /release/v4.1. -> ERR
  • /release/v4.1.4 -> OK
  • /release/v4.1.4.5 -> OK, BUT WEIRD

Parameters

All optional values will have to be returned an Option<&str>.

Constraints

Should support constraints for all types:

  • /users/{id?:constraint}
  • /files/{*path?:constraint}

How we decide to handle segment checks is TBD.

Limitations

Optionals MUST come at the end of a path, segment or section.

We MAY allow multiple chained optionals, undecided.

We won't support defaults in the route. Just use .unwrap_or in your framework of choice.

Prior Art

Changes Needed

  • Blocked by Reconsider router internal structure #143
  • Update parser to explode '?' routes.
  • Figure out how to store this in our tree.
  • Figure out how to insert/delete
  • Figure out how to search
  • Figure out how to display
@CathalMullan CathalMullan linked a pull request Aug 14, 2024 that will close this issue
@CathalMullan CathalMullan closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
@CathalMullan CathalMullan reopened this Aug 19, 2024
@CathalMullan CathalMullan changed the title Consider supporting optional parameters Support optional parameters Aug 19, 2024
@CathalMullan CathalMullan changed the title Support optional parameters Support optional path parameters Aug 21, 2024
@CathalMullan CathalMullan pinned this issue Sep 6, 2024
@CathalMullan CathalMullan linked a pull request Sep 8, 2024 that will close this issue
@CathalMullan CathalMullan unpinned this issue Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant