Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda