Hi, I am new to asp.net core, and react.js component. I wrote a get web api that returns the string like username. How to call this api from react.js component. Please provide a sample code.
Thanks
Hi, I am new to asp.net core, and react.js component. I wrote a get web api that returns the string like username. How to call this api from react.js component. Please provide a sample code.
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Piyush PansuriyaRank #454 · 5.5K reputationPosted Aug 3, 2021, 12:40 AM EDT
Hello,
We call fetch method and we will pass the Url of Web API. This is the Url where our Web API is available and I paste it here. We call the Promise method using then, convert the response into JSON objects, and then we assign this result list to our state object employees property using setState method.
Fetch(“https://localhost:44301/api/Employee”)
.then(res => res.json())
.then(
(result) => {
this.setState({
employees: result
});
}
);
saradalal61 reputationPosted Aug 3, 2021, 12:44 PM EDT
Thanks Piyush for the response. I am still not able to resolve the issue. Please find my code in the zip file. Please make the changes in the code, that will help me in understanding how to call web api from react.js component. This is my first component in react.js.
Thanks