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

240
Visualizações
400 bad request with ReactJs

I'm trying to make a post request to the server,but it returns 400 error. :enter image description here this is react function

const handleSubmit = () => {
  const bookInstanceObject = {
    imprint: imprint,
  };

  axios
    .post('http://localhost:3001/catalog/bookinstance/create', bookInstanceObject)
    .then(res => {
      console.log(res.data);
    })
    .catch(error => {
      console.log(error);
    });
};

and this is the server side:

router.post('/bookinstance/create', (request, response, next) => {
  const body = request.body;

  const bookInstance = new BookInstance({
    imprint: body.title,
  });

  bookInstance
    .save()
    .then(savedBook => {
      response.json(savedBook.toJSON());
    })
    .catch(error => next(error));
});

any idea ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What I think is happening

The front end's handleSubmit function is POSTing to /catalog/bookinstance/create, while the server is expecting it to come to /bookinstance/create.

Simple typo, easy to miss when your stressing over it not working.

How to fix?

Change the URLs to match.

Either:
change the front-end's POST url to /bookinstance/create,
or:
change the server's expected route to router.post('/catalog/bookinstance/create',

Why is it a GET in the error log?

I don't know but I suspect that this error is about a GET request somewhere else in your code.

Please let us know in the comments if the error goes away with this fix. (Assuming my fix works)

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