Closed asiermusa closed 3 years ago
Axios is an HTTP client. This means that you can use it to make request to any website.
If you follow the docs under Usage
you'll see the example request
curl https://api.opentopodata.org/v1/test-dataset?locations=56.35,123.90
made with cURL
. The equivalent request made with axios
would be
axios.get("https://api.opentopodata.org/v1/test-dataset", params: { locations: "56.35,123.90"})
Thanks @ErnestoFGonzalez , I couldn't figure out what axios is.
No api key is needed, so you can test the urls in your browser first. Open topo data should work with any http requests library.
Hi @ErnestoFGonzalez,
Of course I tried with cURL and postman before do the same in my client app with axios, but I receive an error, cors and headers issues every time.
If I do any get request I don't have any problem.
I asked you because in the docs https://www.opentopodata.org, in the last point (paid hosting) I red something related to cors.
CORS (so you can use the API in your frontend webapp)
Ah, I understand now, you're using axios in the browser.
The open software in this repo has full support for browser-based fetch requests and CORS policy. However, the free instance I'm hosting at api.opentopodata.org is configured to block cross-origin requests. These requests effectively bypass the per-IP rate limit, and I want to make sure the server has enough capacity for everyone!
So there are a couple of options to get this working:
config.yaml
file.Hi @ErnestoFGonzalez,
Of course I tried with cURL and postman before do the same in my client app with axios, but I receive an error, cors and headers issues every time.
If I do any get request I don't have any problem.
I asked you because in the docs https://www.opentopodata.org, in the last point (paid hosting) I red something related to cors.
CORS (so you can use the API in your frontend webapp)
Ah my bad. You are right. Your domain needs to be in the CORS origin whitelisted domains
Ah, I understand now, you're using axios in the browser.
The open software in this repo has full support for browser-based fetch requests and CORS policy. However, the free instance I'm hosting at api.opentopodata.org is configured to block cross-origin requests. These requests effectively bypass the per-IP rate limit, and I want to make sure the server has enough capacity for everyone!
So there are a couple of options to get this working:
- Host ajnisbet/opentopodata on your own server with CORS enabled in the
config.yaml
file.- Proxy requests from api.opentopodata.org through your own server, adding the appropriate CORS header
- If you're working on academic research, a personal project, or a small commercial project, send me an email and I can add you to a whitelist on the public api.
Thanks!
I hosted my own server running in a docker container but I think that I have to do something wit CORS in the config.yaml.
Where is that file and what can I change to solve the problem?
Thanks!!
Ah, I understand now, you're using axios in the browser. The open software in this repo has full support for browser-based fetch requests and CORS policy. However, the free instance I'm hosting at api.opentopodata.org is configured to block cross-origin requests. These requests effectively bypass the per-IP rate limit, and I want to make sure the server has enough capacity for everyone! So there are a couple of options to get this working:
- Host ajnisbet/opentopodata on your own server with CORS enabled in the
config.yaml
file.- Proxy requests from api.opentopodata.org through your own server, adding the appropriate CORS header
- If you're working on academic research, a personal project, or a small commercial project, send me an email and I can add you to a whitelist on the public api.
Thanks!
I hosted my own server running in a docker container but I think that I have to do something wit CORS in the config.yaml.
Where is that file and what can I change to solve the problem?
Thanks!!
I can't test it right now, but try to set DEFAULTS["access_control_allow_origin"] = "*"
at line 19
in opentopodata/opentopodata/config.py
to allow all origins.
Ah, I understand now, you're using axios in the browser. The open software in this repo has full support for browser-based fetch requests and CORS policy. However, the free instance I'm hosting at api.opentopodata.org is configured to block cross-origin requests. These requests effectively bypass the per-IP rate limit, and I want to make sure the server has enough capacity for everyone! So there are a couple of options to get this working:
- Host ajnisbet/opentopodata on your own server with CORS enabled in the
config.yaml
file.- Proxy requests from api.opentopodata.org through your own server, adding the appropriate CORS header
- If you're working on academic research, a personal project, or a small commercial project, send me an email and I can add you to a whitelist on the public api.
Thanks! I hosted my own server running in a docker container but I think that I have to do something wit CORS in the config.yaml. Where is that file and what can I change to solve the problem? Thanks!!
I can't test it right now, but try to set
DEFAULTS["access_control_allow_origin"] = "*"
atline 19
inopentopodata/opentopodata/config.py
to allow all origins.
In case you want to use it in production I recommend you set it to your domain, e.g. "https://example.com"
.
If you don't have a config.yaml
file make one by copying example-config.yaml
to config.yaml
in the root directory of this repo:
cp example-config.yaml config.yaml
Then replace the line
access_control_allow_origin: null
with
access_control_allow_origin: "*"
You can then continue adding your datasets to config.yaml
. You don't need to modify any python files.
Also this conversation makes me think CORS should be enabled by default in the example config (though will still be disabled in the public API).
If you don't have a
config.yaml
file make one by copyingexample-config.yaml
toconfig.yaml
in the root directory of this repo:cp example-config.yaml config.yaml
Then replace the line
access_control_allow_origin: null
with
access_control_allow_origin: "*"
You can then continue adding your datasets to
config.yaml
. You don't need to modify any python files.Also this conversation makes me think CORS should be enabled by default in the example config (though will still be disabled in the public API).
@ajnisbet, @ErnestoFGonzalez it works! thanks a lot!
With my self-hosted docker app can I do requests as I want?
Thank you!
Hi,
Is it possible to make a request using axios or you need to pay for some key for that?