-1

Trying to write a simple route, getting a record by it's id property/column

const router = require("express").Router();    
router.get("/record/:id", getRecordById)    // CHANGE HERE

This is how I'm able to use for frontend ajax -

http://localhost:3001/record/1

What do I need to change, to be able to use the route as

http://localhost:3001/?record=1
Kiran Racherla
  • 219
  • 3
  • 12

2 Answers2

2

You should create a route like this.

router.get("/", function (req, res) {
  // Get record id
  const record_id = req.query.record;
});
1

In your case

API: router.get("/record", getRecordById)

URL: http://localhost:3001/record?id=1

Get the query string in api: req.query.id

Peter
  • 32
  • 2