Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda