Highlighted

Making rest call from javascript use api.

Maddy737

22-05-2018

Hi All,

Can someone explain me if we can make rest api call from javascript use api with an example?

Also, we are using reactJS to make a call to backend, can we achieve the same with javascript use api and should we use reactJS only?

Thanks

Madhu

Replies

Highlighted

Maddy737

23-05-2018

But this will be a server call right? My requirement is to make client calls like react JS do. Any best approach then using reactjs???

Highlighted

smacdonald2008

23-05-2018

If you requirement is to make a call on the client - then you can use react to make a rest call. This could be done in script file located in a client lib. See this thread for more information -- json - Making REST calls from a react component - Stack Overflow

Having said that - if the requirement is to make a call to a Restful web service - like a Google service - and display the result set in a component -- its better to make the call on the server using Java/WCMUsePojo - as shown in the above article.

Highlighted

Maddy737

28-05-2018

Hi smacdonald2008,

Yeah i agree with you. But in my case application do lot of api calls (REST) to other layers such as SAP. If there are so many requests it will put lot of load on publishers as java, javascript use api is service side. Hence, am looking for other alternative which can be handled at aem level.