restify / restify/node-restify

Documentation to support route with colon

Open
#1,780 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.7k
Forks
975
Avg merge
1d 6h
Merged PRs (30d)
5

Description

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.

Contributor guide

Open the contributing guide

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 locating the existing route documentation and the routing behavior for colon-containing paths. Use the examples in this issue to determine which form handles a literal colon and preserves the named parameter, then document that form and verify the resulting requests are covered clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.