We help IT Professionals succeed at work.

New to React, new to APIs

Michael Sterling
on
I've created a react app and an API that I'm trying to make a call to through my react app. How do I do this? I'm doing this on my local machine (lap top). I'm using .Net Core 2.2 for my react app and .Net Core 3.1 for my API. What files or code other information can I / should I share to get the best help with this. I set up the React project right out of the box in Visual Studio 2019 as instructed by a basic tutorial. My API has been tested using swagger and it does work. Its very basic right now. React Error
Comment
Watch Question

Distinguished Expert 2019

Commented:

is your api service actually running?

Michael SterlingWeb Applications Developer

Author

Commented:
Yes it is currently running.
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:

You need to install an AJAX library like Axios that you can use to make calls to your API.


You can read more about it in the official docs here


https://reactjs.org/docs/faq-ajax.html

Most Valuable Expert 2017
Distinguished Expert 2019

Commented:

From your screen shot it appears you are already using an AJAX library (confused by the what do I need to add to talk to an API question).


This thread seems to discuss this issue


https://github.com/swagger-api/swagger-ui/issues/3403


Several solutions suggested - one was concerning AWS not returning headers the other had to do with CORS not being setup correctly.


It is possible for your API's to work in a tool like Swagger or Postman and not work in the browser due to CORS not being set correctly - so you can check that.

Web Applications Developer
Commented:
I wound up just using: Moesif Orign & CORS Changer - https://chrome.google.com/webstore/detail/moesif-orign-cors-changer/digfbfaphojjndkpccljibejjbppifbc?hl=en-US

It solves my problem for now.