Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ntsd/jekyll-http-request
Jekyll Liquid Filter for HTTP requests, helps get HTTP response data to the page content and cache
https://github.com/ntsd/jekyll-http-request
jekyll jekyll-plugin liquid liquid-filters ruby
Last synced: about 1 month ago
JSON representation
Jekyll Liquid Filter for HTTP requests, helps get HTTP response data to the page content and cache
- Host: GitHub
- URL: https://github.com/ntsd/jekyll-http-request
- Owner: ntsd
- License: mit
- Created: 2023-08-01T22:42:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-17T21:41:58.000Z (8 months ago)
- Last Synced: 2024-09-23T02:07:26.540Z (3 months ago)
- Topics: jekyll, jekyll-plugin, liquid, liquid-filters, ruby
- Language: Ruby
- Homepage: https://rubygems.org/gems/jekyll-http-request
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-jekyll-plugins - **jekyll-http-request** - http-request](https://rubygems.org/gems/jekyll-http-request)) by Jirawat Boonkumnerd -- Liquid Filter for HTTP requests, helps get HTTP response data to the page content and cache. (Other)
README
# Jekyll HTTP Request
[![Gem Version](https://img.shields.io/gem/v/jekyll-http-request.svg)](https://rubygems.org/gems/jekyll-http-request)
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`:```yaml
plugins:
- jekyll-http-request
```Alternatively using git repository for gem `gem "jekyll-http-request", :git => "git://github.com/ntsd/jekyll-http-request.git"`.
## Usage
```rb
{{ | http_request: , , }}
```- `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](https://jekyllrb.com/tutorials/cache-api/) for the next time it call the same request. The cache will clear after the site init.
## Examples
### HTTP GET
```rb
{{ '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.
```rb
{{ 'https://httpbin.org/anything' | http_request }}
```### HTTP POST
```rb
{{ 'http://httpbin.org/anything' | http_request: 'POST' }}
```### With headers
headers will separate by pipe (|) and separated key-value by colon (:).
```rb
{{ '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
```rb
{{ 'http://httpbin.org/anything' | http_request: 'POST', '', 'body' }}
```### With JSON body
use `capture` to define `jsonBody` variable.
```rb
{% 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
```rb
{{ 'https://raw.githubusercontent.com/ntsd/jekyll-http-request/main/README.md' | http_request: 'GET', '', '' | markdownify }}
```### Unit Testing
To run unit test use `rake` command.
```rb
rake
```