lukeed / lukeed/regexparam

Path params that contain slashes

Open
#30 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
599
Forks
26
PR merge metrics
No merged PRs in 30d

Description

What's the recommended way to handle path parameters that may contain slashes?

For example, we have a `/docs/` path in our app that contains nested paths or arbitrary length. For example:

```
/docs/foo
/docs/foo/
/docs/foo/bar
/docs/foo/bar/baz
```

We can match these paths in regexparam using `/docs/*` which works fine if all we want to do is match the path without extracting the param value, but if we want to extract that param:
1. Using a `*` parameter name is weird DX because it requires using `params['*']` syntax instead of the more familiar `params.rest` syntax. This also makes IDE autocomplete problematic; in VSCode, autocomplete won't work when you type `params.` so it's harder for developers to discover that param, although if you know to type `params.['` then it may work. (BTW, worse autocomplete was a tradeoffs of changing from `wild` to `*` for the wildcard parameter name.)
2. I must manually strip trailing slashes, which makes the behavior of wildcard params different from all other params where slashes are automatically stripped by default.

Is there a solution for slashful params other than building our own Regex? (Where we'll also lose the nice DX and autocomplete because TS literal types won't work with regexes)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading regexparam's route matching and parameter extraction behavior, focusing on wildcard patterns such as `/docs/*` and how trailing slashes are handled. Determine whether slash-containing parameters can support familiar named access and TypeScript autocomplete without custom regular expressions; done means the supported behavior and API are clearly defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.