Jekyll Liquid Filter for HTTP requests, helps get HTTP response data to the page content and cache.
gem 'jekyll-http-request'
to your site’s Gemfile.bundle
._config.yml
:plugins:
- jekyll-http-request
Alternatively using git repository for gem gem "jekyll-http-request", :git => "git://github.com/ntsd/jekyll-http-request.git"
.
{{ <url> | http_request: <http_method>, <headers>, <body> }}
url
: url of the request.http_method
: the HTTP method, only support GET and POST for now.headers
: headers will separate by pipe (|) and separated key-value by colon (:).body
: http request body.** The liquid filter required all parameters, set to empty string if not provided.
The response will cache to Jekyll::Cache for the next time it call the same request. The cache will clear after the site init.
{{ 'http://httpbin.org/anything' | http_request: 'GET', '', '' }}
if the url starts with https
will force request with ssl.
{{ 'https://httpbin.org/anything' | http_request: 'GET', '', '' }}
{{ 'http://httpbin.org/anything' | http_request: 'POST', '', '' }}
headers will separate by pipe (|) and separated key-value by colon (:).
{{ 'http://httpbin.org/anything' | http_request: 'GET', 'key:value|key2:value2', '' }}
{{ 'http://httpbin.org/anything' | http_request: 'POST', '', 'body' }}
use capture
to define jsonBody
variable.
{% capture jsonBody %}{ "foo": "bar" }{% endcapture %}
{{ 'http://httpbin.org/anything' | http_request: 'POST', '', jsonBody }}
example fetch Github README.md then render by markdownify
{{ 'https://raw.githubusercontent.com/ntsd/jekyll-http-request/main/README.md' | http_request: 'GET', '', '' | markdownify }}