简体   繁体   中英

Consuming an API from a Salesforce Commerce Cloud controller

Inside a SFCC custom controller, at a certain point I need to consume an API and wait for its response before continuing. In fact, the my controller's response depends on the API's response itself.

Unless I'm mistaken, the SFCC documentation doesn't provide any code sample about that.

Express apparently provides a solution (see the very beginning of https://zellwk.com/blog/async-await-express/ for example), but SFCC middleware doesn't seem to handle the async keyword when defining a request handler.

Can anybody help on this one?

Thanks

There is no way to handle async code on SFCC natively. And you need to change your code's structure according to this restriction. But you can use some jobs as a workaround.

Please check this link for more information about this concept: https://medium.com/@osapishchuk/asynchronous-execution-within-sfcc-9cc6226e1ac6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM