DEV Community

Daniel Lee
Daniel Lee

Posted on • Edited on

TIL: api route paths can be designed with the hypen (-) and the dot (.)

API routes can be designed to use the hypen and dot for useful purposes. For instance, to pass/parse multiple pieces of information.

Example usage of the hypen

  Route path: /flights/:from-:to
  Request URL: http://localhost:3000/flights/LAX-SFO
  req.params: { "from": "LAX", "to": "SFO" }
Enter fullscreen mode Exit fullscreen mode

Example usage of the dot

  Route path: /plantae/:genus.:species
  Request URL: http://localhost:3000/plantae/Prunus.persica
  req.params: { "genus": "Prunus", "species": "persica" }
Enter fullscreen mode Exit fullscreen mode

There're other ways to pass multiple values to a route path such that uses an array or the same parameter.

Example

  Route path: /test
  Request URL1: https://localhost:3000/test?array=a&array=b&array=c
  Request URL2: https://localhost:3000/test?array[]=a&array[]=b&array[]=c
Enter fullscreen mode Exit fullscreen mode

In the code

  app.get('/test', function(req,res){
    console.log(req.query.array); // array=[a,b,c]
    res.send(200);
  });
Enter fullscreen mode Exit fullscreen mode

Note that query string exposes sensitive data to clients, so sensitive data shouldn't be put into a query string.

API Trace View

Struggling with slow API calls? 👀

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay