Skip to main content
Answer

Can I make API calls from the browser?

  • November 28, 2023
  • 2 replies
  • 233 views

I’d like to use the Core API to generate draft messages. In the docs, I notice that there are examples for use in JavaScript (including fetch and XHR APIs). When I tested this code in the browser console, the request was rejected due to cross-origin headers (specifically the requesting origin was not allowed by Access-Control-Allowed-Origins). Is calling the API from the browser supported? And if so, how would I go about configuring CORS headers?

Thanks!

Best answer by jason

No, this is not supported for security reasons.

If you need to initiate requests from the browser, we advise issuing a request to your server, and having the server perform the Front REST API request (so no API credentials are exposed to the browser), and return the result to the browser. This also allows you to utilize caching results where appropriate. 

2 replies

jason
Forum|alt.badge.img+8
  • Fronteer
  • Answer
  • November 28, 2023

No, this is not supported for security reasons.

If you need to initiate requests from the browser, we advise issuing a request to your server, and having the server perform the Front REST API request (so no API credentials are exposed to the browser), and return the result to the browser. This also allows you to utilize caching results where appropriate. 


  • Author
  • Conversationalist
  • November 28, 2023

Thanks - I suspected as much. No problem at all, thank you for your help 😀