I've seen it used in multiple places, the latest include GitLab's URL structure and some software I work on at my company.
It goes like this:
https://some.gitlab.com/group/project/-/tree/main
or for some endpoints of a service
https://some.service/-/healthcheck
My question is, what is its purpose? Afaik it has no special effect unless the underlying HTTP framework uses it somehow?
The exact, precise reason is often project-specific. However, the char -
could often be used as wildcard or neutral placeholder in routes.
For instance, if you have routes that would accept an optional account identifier such as:
https://some.service/:account_id/healthcheck
Then you could use the -
as a placeholder without having multiple route definitions (that sometimes may end up making the route matching more convoluted). In this case, you could end up having routes like:
https://some.service/-/healthcheck
https://some.service/18/healthcheck
In the first case, the account is not explicitly provided. Perhaps there are cases where the resource ID (in this case the account ID) is inferable from the context.
Since you explicitly mentioned GitLab, and given their code is open source, I went through the exercise of figuring out more precisely why they use -
. I started from their routes.rb
file, where I found a reference to a /-/ scope.
From there, blaming the code changes, I ended up at the following tickets:
TL;DR; They are prefixing certain routes with -
as it speeds up the performance of the app when the router needs to determine the appropriate controller/action for a given request.
Every time a Rails controller has to match an endpoint, it has to do this giant regex comparison. I've seen this show up in our performance traces, somewhere.