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

272
Visualizações
How to send Json data to an API in React

I have the following on my frontend: Note: My JSON file in a state

    const postData = () => {
        console.log("This is our data", state);
        const url = "http://localhost:3000/postData";
        fetch(url, 
        {method: 'POST', // or 'PUT'
        headers: { 'Content-Type': 'application/json',},
        body: JSON.stringify(state),
    })
    .then(response => response.json())
    .then(data => {
  console.log('Success:', data);
})
.catch((error) => {
  console.error('Error:', error);
});

}

This front end is working. However, I want to post this data to an API such that when someone types:

localhost:3000/postData

They must get my JSON file that was in my state on the front end

Here is the backend code that I'm struggling with:

app.post("/postData", (req, res) => {
    console.log(req.body);
    const result = req.body.state
    res.send(result);

});
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

body: JSON.stringify({
            state: state,
        })
about 4 years ago · Santiago Gelvez Relatório

0

I think you can try this way

this.apiService.post('URl', body).then((data) => {
            if (data) {
            }
        });
about 4 years ago · Santiago Gelvez 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