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

96
Views
fetch post with variable id in url and session

im pretty new with restAPI, fetch..., so Im having problems understanding this. On a saveButton press, I want to use fetch to post json data. Im on the site: https://example.com/22 The api url is like: https://example.com/api/save/22. 22 is a variable user_id, different for every logged in user.

When Im using routing to navigate, I use:

router.post('',async(req,res)=>{
const signedsessions = req.cookies['connect.sid'];
const projectId = parseInt(req.params['projectID'],10) || 0
...

So I can access the ID and the session quite easily. But how can I access these projectId and signedsessions when using a simple fetch to post a json? Like this:

export function saveData(data, id, session){
id = parseInt(id, 10) || 0;
...
const projId = (id > 0)? '/' + id : '';
const options = {
method:'POST',
headers: {
   'Content-Type': 'application/json',
   'Cookie': 'connect.sid=' + session
},
body: JSON.stringify(data)
};
return fetch('https://example.com/api/save + projID, options)
   .then(res => res.json())
   .catch(err => console.log(err));

}

Maybe Im understanding something completely wrong concerning routing and restAPIs. Or is there a trick how to access these informations?

about 4 years ago · Juan Pablo Isaza
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!