Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "access-control-allow-origin: *" header to API responses to allow… #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

craigahobbs
Copy link

… cross-origin web clients to use the APIs

This resolves issue #41

@craigahobbs
Copy link
Author

craigahobbs commented Dec 22, 2022

Here's a little more information on why this is useful. I created the following dashboard to track my Python and JavaScript package downloads:

https://craigahobbs.github.io/downloads/

The dashboard is a static, client-rendered web application - it has no backend. It can only load data from its domain or from cross-origin domains (e.g., pypistats.org and api.npmjs.org) that provide the CORS header ("access-control-allow-origin: *").

The api.npmjs.org API responds with the CORS header so that I can use it directly:

https://api.npmjs.org/downloads/range/2022-06-22:2022-12-22/markdown-model

https://github.com/craigahobbs/craigahobbs.github.io/blob/main/downloads/downloads.mds#L183

However, the pypistats.org API does not respond with the CORS header, so I can't use it directly. Instead, I periodically download and commit the API responses locally so that I can load them.

https://github.com/craigahobbs/craigahobbs.github.io/blob/main/downloads/downloads.mds#L212

The dashboard would be better if I could use the pypistats.org API directly, as the data would always be up-to-date, and the periodic download step would no longer be required.

Let me know if you have any questions about the pull request. Thanks!

@mightbesimon
Copy link

Same situation as the above! My personal website tracks my publications, https://mightbesimon.com 🥺

@craigahobbs
Copy link
Author

@crflynn any interest in this pull request? If no, I'll delete it. I don't see any downside to it though. It just enables web clients to use the API directly. Generally speaking, these are the best-behaved clients you'll see - they respect your cache headers and maintain connections sanely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants