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 get_json function #465

Closed
wants to merge 2 commits into from
Closed

Add get_json function #465

wants to merge 2 commits into from

Conversation

RealOrangeOne
Copy link
Contributor

@RealOrangeOne RealOrangeOne commented Oct 7, 2018

Add a template function to request JSON data from remote endpoints. This is currently a very minimal implementation, which doesn't cache anything between runs (the cache lives purely in-memory). Future iterations may include a filesystem cache, and support for other datatypes (eg CSV). I added a fairly naive example to the docs site which tests both the response, and whether the response is correctly cached.

Adding support for remote content like this is a controvertial feature in static site generators, because it both adds an external dependency on the upstream API value, but also means the site requires an active internet connection to build. I personally use it quite a lot to fetch fairly fixed metadata, or to build custom widgets for things which expose an API, but have fairly terrible embed support. If you don't actually use the function, then no requests are actually made.

@RealOrangeOne
Copy link
Contributor Author

(Netlify is failing because it can't find the new function, which is to be expected)

@Keats
Copy link
Collaborator

Keats commented Oct 7, 2018

This looks like a duplicate of #379 ? Despite the name of the PR it also loads JSON now.

@RealOrangeOne
Copy link
Contributor Author

Not quite. By the looks of it, #379 loads data from the project itself. This requests it from a remote.

@Keats
Copy link
Collaborator

Keats commented Oct 8, 2018

See the discussion from #379 (comment)

#379 is starting with local files but the goal is to add remote to it afterwards

@RealOrangeOne
Copy link
Contributor Author

aha, in that case yes, this is a duplicate. And that looks like a far more robust implementation anyway 👍

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