Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

275
Views
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 answers
Answer question

0

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

0

I think you can try this way

this.apiService.post('URl', body).then((data) => {
            if (data) {
            }
        });
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!