Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

79
Views
Trying to send more than one parameter to a GET function

I am trying to send more than one parameter to the GET function. Right now I have:

const response = await fetch(`http://localhost:5000/demos/price/${numticket}/${carry}`);

And I am trying to send this information to (but the request does not go to the function):

app.get('/demos/price/:ticket/:carry', async(req, res)=>{
  //console.log('in index');
  try{
      let ticket = req.params.ticket;
      let carry = req.params.carry;
  } catch(err){
    console.log(err.message);
  }
});

Is this how I go about doing this or do I have it completely wrong?

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

You're capturing path parameters correctly, except you don't need the try/catch block around setting variables since you're not doing anything that can throw an error. This works as expected for me:

app.get('/demos/price/:ticket/:carry', (req, res)=>{;
  res.send(req.params.ticket + ' ' + req.params.carry)
});

(Sent request in my terminal via curl like so: curl localhost:3000/demos/price/aaa/bbb, but the way you're sending it in JS is correct as well)

Is it possible that it's working properly but you're just not noticing anything happening because you're just setting variables and not logging anything or returning a response?

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs