Rishabh Sethi
Rishabh Sethi

Reputation: 55

Making 3rd party API calls from NodeJs as backend and rendering the data received in ReactJs frontend

Since I'm new to API calls, I'm having issues regarding making API calls from backend. I've a form that takes AccessToken from the user. Based on the token received, I've to make an API call to 3rd party API. It should return the roles that the particular user has. The token has to be sent as headers. How to make the API call if the Frontend is on ReactJs and Backend is running on NodeJs.

Upvotes: 1

Views: 538

Answers (1)

Ajay Gupta
Ajay Gupta

Reputation: 2033

Basically you have three entities at work here.

  1. Your Backend - Node
  2. Your Client - React
  3. External Service - Some other service where you are making the call from your backend

Assuming the flow of your application is like this:

Your Client -> (asks for some resource) Your Backend -> (requests an api from external service)

So you can expose an endpoint on Your Backend, which Your client will call and in turn Your Backend will call an External Service using a library like Axios or the inbuilt Fetch API. As soon as Your Backend gets a response from the External Service, you can send the received response to Your Client.

Hope it helps!

Upvotes: 2

Related Questions