A
A
Anastasia2021-09-04 10:13:43
JavaScript
Anastasia, 2021-09-04 10:13:43

How to get data from another site using API?

Hello.
I have a website about cryptocurrency and I want to create a blog for it.
When writing a post in a text editor (normal textarea), I want to be able to receive data via the API from the site https://api.coinpaprika.com/
In a simple version, it should look like this:
61331b7952dc3965352550.jpeg

That is, I write a post, I indicate in it, np { { Price/BTC }} and in the editor on the side I immediately get the actual data from the site, e.g. 50336.70518386 $

I have not worked with the API before and I will be grateful if you tell me how

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-09-04
@Rsa97

Judging by the absence of CORS headers in the responses of this API, you will not be able to get this data directly from your page, only through the backend.
For the rest, you process the onInput event, analyze the entered text, if you find a field that needs to be filled in, then make an AJAX request to your backend, get the necessary data from it, substitute it in the text and change the contents of the second field.
You need to add a cache that saves the received values ​​so as not to waste time requesting them again. When you open a page, you can prepopulate this cache with your most used data. You can also get data not by one field, but by a group, for example, when you meet Name / BTC, you can immediately request all data about bitcoin.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question