M
M
Mishcake2020-01-16 17:01:57
PHP
Mishcake, 2020-01-16 17:01:57

How to access the API through an intermediary site?

Hello. Please let me know how correct I am.
There is a website builder that allows you to add custom js code (located on domain #1). There is an external PHP script (located on domain No. 2) that sends / collects data from the API of a third-party service. There is an API (domain number 3).
What is the best way to organize requests to the API of a third-party service from the custom code of the site builder?
I see two options. The first is such a bicycle:
1. We implement a php script for accessing the API, we place it on our host.
2. From the js script on the constructor, we access the php script on our host.
3. php script sends a request, receives a response and returns to the js script.
4. Based on the response, the js script does the necessary actions on the page.
The second is to use XMLHttpRequest (? I'm not familiar with js yet, this is the only thing I googled and that seems to fit my task), sending a request directly from the custom constructor form.
How is it better? How is it correct? Please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2020-01-16
@inoise

No one will let you access another domain from your browser. We'll have to do a layer in any case on the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question