node-restify icon indicating copy to clipboard operation
node-restify copied to clipboard

Documentation to support route with colon

Open dodtsair opened this issue 5 years ago • 0 comments

Feature Request

The documentation covers routes very well, but it does not cover some of the exceptional cases. For example when setting up a route the character colon has special meaning. As such if I use colon in the route it changes the URL handled by that route. So how do we make a route that handles a URL with a literal colon in it?

Use Case

A couple API end points

  1. GET /hello:bob
  2. GET /hello:name=bob
  3. GET /hello:full-name=bob%20smith

I want to setup a route that will handle these requests:

function respondName(req, res, next) {
  res.send('hello ' + req.params.name);
  next();
}

I could try this:

server.get('/hello:name', respond);

How ever now the program will output: hello :bob It has the colon embedded in the argument.

Now when I try to escape it, there is no documentation how. Which of the following would allow a colon to appear in the URL.

Use slash escape: server.get('/hello\::name', respond); Regex literal server.get('/hello[:]:name', respond); Percent encoding: server.get('/hello%3A:name', respond); Regex object: server.get(/^\/hello:[^:]+/, respond); Repeat special character: server.get('/hello::name', respond); Repeat special character twice: server.get('/hello:::name', respond);

We have URLs that have colons and identifiers in them. We are trying to upgrade to the latest restify

Are you willing and able to implement this?

We could help update the documentation regarding this, but need to know how it should be done.

dodtsair avatar May 03 '19 18:05 dodtsair