The project is in a healthy, maintained state
Jekyll Liquid Filter for HTTP requests, helps you get HTTP response data to the page content.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.0

Runtime

>= 3.7, < 5.0
 Project Readme

Jekyll HTTP Request

Gem Version

Jekyll Liquid Filter for HTTP requests, helps get HTTP response data to the page content and cache.

since many people using UTF-8 nowaday, so I have decide to force encoding the response body to UTF-8.

Installation

  1. Add gem 'jekyll-http-request' to your site's Gemfile.
  2. run bundle.
  3. Add the following to your site's _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".

Usage

{{ <url> | http_request: <http_method>, <headers>, <body> }}
  • url: url of the request.
  • http_method: (optional) the HTTP method, only support GET and POST for now.
  • headers: (optional) headers will separate by pipe (|) and separated key-value by colon (:).
  • body: (optional) http request body.

** The liquid filter left side 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.

Examples

HTTP GET

{{ 'http://httpbin.org/anything' | http_request }}
# or
{{ 'http://httpbin.org/anything' | http_request: 'GET', '', '' }}

HTTPS GET

if the url starts with https will force request with ssl.

{{ 'https://httpbin.org/anything' | http_request }}

HTTP POST

{{ 'http://httpbin.org/anything' | http_request: 'POST' }}

With headers

headers will separate by pipe (|) and separated key-value by colon (:).

{{ 'http://httpbin.org/anything' | http_request: 'GET', 'key:value|key2:value2' }}
# of
{{ 'http://httpbin.org/anything' | http_request: 'GET', 'key:value|key2:value2', '' }}

With body

{{ 'http://httpbin.org/anything' | http_request: 'POST', '', 'body' }}

With JSON body

use capture to define jsonBody variable.

{% capture jsonBody %}{ "foo": "bar" }{% endcapture %}
{{ 'http://httpbin.org/anything' | http_request: 'POST', '', jsonBody }}

Fetch Markdown and Render

example fetch Github README.md then render by markdownify

{{ 'https://raw.githubusercontent.com/ntsd/jekyll-http-request/main/README.md' | http_request: 'GET', '', '' | markdownify }}

Unit Testing

To run unit test use rake command.

rake