Logo

dev-resources.site

for different kinds of informations.

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

Published at
9/16/2024
Categories
study
web
api
backend
Author
dleedev365
Categories
4 categories in total
study
open
web
open
api
open
backend
open
Author
10 person written this
dleedev365
open
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.

study Article's
30 articles in total
Favicon
Let's build an app
Favicon
Day 2: Leetcode
Favicon
Career Boost: Cert IV Hospitality (SIT40416) RPL
Favicon
German Health Insurance for International Students: A Complete Guide
Favicon
Wi-Fi Components - 500-420 CAAPA Exam Guide
Favicon
Switching Packets - Cisco 010-151 DCTECH Exam Guide
Favicon
Wireless Interference - 500-301 CCS Exam
Favicon
Advantages and Disadvantages of Wi-Fi - 500-325 CSA Exam Guide
Favicon
What an IP Address Represents - Cisco 300-420 ENSLD Study Guide
Favicon
The Electromagnetic Spectrum - 500-425 CAAA Study Guide
Favicon
Computing a Global Address - Cisco 010-151 DCTECH Exam Guide
Favicon
Internet Protocol Version 4 - Cisco 300-420 ENSLD Study Guide
Favicon
Internet Protocol Version 6 - Cisco 300-430 ENWLSI Exam Guide
Favicon
Physical Addresses - Cisco 300-415 ENSDWI Study Guide
Favicon
Calculating Prefixes Using Skips - Cisco 300-425 ENWLSD Exam
Favicon
Microsoft 365 Active Directory - MS 900 Study Guide
Favicon
Why Two Addresses? - Cisco 300-425 ENWLSD Study Guide
Favicon
TIL: api route paths can be designed with the hypen (-) and the dot (.)
Favicon
Students Club Provides Study abroad Consultants in Faisalabad
Favicon
FAQ page in HTML only
Favicon
CompTIA A+ Study Guide Core 1 and Core 2 Exam Info
Favicon
Education Loan For Study Abraod
Favicon
The Biggest Difficulties Students Face When Deciding to Study Abroad
Favicon
Conch
Favicon
How to apply with MOI certificate at a UK University
Favicon
YES Germany: Your Go-To Study Abroad Consultant in Udaipur
Favicon
Assessment Help
Favicon
Adamjee notes for class 9 physics
Favicon
Study MBBS in Europe
Favicon
A Comprehensive Guide to Obtaining a UK Study Visa

Featured ones: