Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
How to pass variable to GET request after receiving it from POST request

Can't figure out how to pass a variable to GET request after receiving it from the frontend.

 app.post('/subcategories', (req, res) => {
  //receive category id from front
   const category_id = req.body.category;
 })

 app.get('/subcategories', (req, res) => {
    // need to replace the 25 with the variable I recieved from the above POST request
    const category_id = 25;
    db.query('SELECT subcategory_name FROM subcategories WHERE category_id=(?)',
    [category_id],
    (err, result) =>{
      res.send({result})
    });
 })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can directly pass the category_id to GET using query parameters.

Do something like :

/subcategories?category_id=25

catch it in the GET api using :

let category_id = req.query.category_id
about 4 years ago · Juan Pablo Isaza Report

0

you can pass category_id as a query when making a get request and grab the category_id in the '/subcategories' route using req.query.

make get requests like this.

/subcategories?categoryid=25

get it in a query object like this.

let categoryId = req.query.categoryid
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!