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

203
Vistas
Endpoint URL not found in axios PUT endpoint

When pressing a button, my app is suppose to subtract 1 from the current Quantity in the database where the name of the item is "CrossBag"

My PUT endpoint on the client:

confirm = () => {
    axios.put(`http://localhost:5000/merch/CrossBag`, {
        Quantity: this.state.merchInfo[0].Quantity - 1,
        });
};

The structure of my table merch where Name is the primary key: enter image description here

The server side of the endpoint:

app.put('/merch/:name', function (req, res) {
  const { name } = req.params;
  const { Quantity } = req.body;

  connection.getConnection(function (err, connection) {
     if(err) {
         console.log(err)
         return
     }

     connection.query(`UPDATE merch SET Quantity = ${Quantity} WHERE name = ${name}`, function (error, results, fields) {
       
      if (error)
      {
        throw error;
      }
    });
   });
});

When I press the button though it states:

PUT http://localhost:5000/merch/CrossBag 404 (Not Found)

I'm a bit confused on how to update specifically that row's Quantity. I read that you need some kind of ID to specify which row to change, so I made that ID my Primary Key (Name).

Can anyone provide me any guidance?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to define the route like below:

// this will match route like /merch/CrossBag or /merch/Blanket
app.put('/merch/:name', function (req, res) {
  const {name = '' } = req.params; 
  connection.getConnection(function (err, connection) {
     if(err) {
         console.log(err)
         return
     }
   });
});
about 4 years ago · Juan Pablo Isaza Denunciar
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