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

102
Vistas
no body in fetch put for node express

I cannot get the body correct on the server. If I use content type of json, I get an empty body, if I use urlencoded I get the body but not parsed. Looks like this { { "title": "New Title" }: '' } I would expect to just access a property on the body like so, req.body.title. I'm using latest version of node and express.

Client

function editMovies() {
    //var putMethod = { method: 'PUT', headers: { "Content-Type": "content-type: application/json" } };
    var putMethod = { method: 'PUT', headers: { "Content-Type": "application/x-www-form-urlencoded" } };
    putMethod.body = JSON.stringify({ "title": "New Title" });
    fetch("/api/movies/2", putMethod).then(function (response) {});
}

Server

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.put('/api/movies/:id', function (req, res) {
    var id = req.params.id;
    console.log('put called with:' + req.body.title);
});
about 4 years ago · Santiago Gelvez
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