I have a task at work to make a POST call to an API in a reactjs UI onclick. I believe, after the POST call, the API is going to supposed to send a series of JSON objects. I am trying to capture those JSON objects in a JSON Array. I am fairly new to react and axion any help would be appreciated.
I have make post calls from my UI to dummy apis to check responses on chrome console. Current I am facing some problems with the actual API. But I am trying to get ahead on how to hold the JSON response from the API.
import React from 'react';
import './App.css';
import axios from 'axios';
class App extends React.Component{
obj = {
"name": "abc",
"Street":"Legacy",
"City":"Plano",
"State":"Texas",
"ZIP":75024
};
constructor(){
super()
this.state = {
address:[]
}
this.handleClick=this.handleClick.bind(this)
}
handleClick(){
axios.post('https://jsonplaceholder.typicode.com/posts', {
title: 'foo',
body: 'bar',
userId: 1
})
.then((response) => {
console.log(response);
}, (error) => {
console.log(error);
});
console.log("I am working to Validate")
}
In my actual reactJS project I am going to be sending the JSON object which I have currently hardcoded as obj in a POST call. I will be receiving JSON Objects in the response which I want to capture in address:[]