Making rest call from javascript use api.

Avatar

Avatar

Maddy737

Avatar

Maddy737

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

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

22-05-2018

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

Avatar

Maddy737

Avatar

Maddy737

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

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
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.

Avatar

Avatar

Maddy737

Avatar

Maddy737

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.

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

28-05-2018

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

Avatar

Avatar

Maddy737

Avatar

Maddy737

Maddy737

28-06-2018

JS USE API is still a server call right?