Expand my Community achievements bar.

Making rest call from javascript use api.

Avatar

Level 4

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

6 Replies

Avatar

Level 10

A better approach is to use WCMUsePojo with HTL to make a Restful call to a 3rd party service - as explained here: Creating an Adobe Experience Manager 6.4 HTL Component that displays data from a Restful Web Service

Avatar

Level 4

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???

Avatar

Level 10

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.

Avatar

Level 4

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.

Avatar

Level 10

Then use the JS USE API and then make a Rest call using JS.

Avatar

Level 4

JS USE API is still a server call right?