jalendport/craft-fetch

Utilise the Guzzle HTTP client from within your Craft templates.

Maintainers

πŸ‘ jalendport

Package info

github.com/jalendport/craft-fetch

Documentation

Type:craft-plugin

pkg:composer/jalendport/craft-fetch

Fund package maintenance!

jalendport

Statistics

Installs: 27 811

Dependents: 1

Suggesters: 0

Stars: 23

Open Issues: 7

2.0.0-beta.1 2023-06-08 22:22 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT dd712e249c722ce1cdd2837ab88b96f84eeabe07

cmsGuzzlefetchCraftcraftcmscraft-plugin

This package is auto-updated.

Last update: 2026-06-09 04:37:01 UTC


README

πŸ‘ icon

Fetch plugin for Craft CMS 3.x

Utilise the Guzzle HTTP client from within your Craft templates.

Requirements

This plugin requires Craft CMS 3.0.0 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require jalendport/craft-fetch
    
  3. In the Control Panel, go to Settings β†’ Plugins and click the β€œInstall” button for Fetch.

Using Fetch

This plugin is built to work with the standard Guzzle request options

Parameters

Parameter Example value
client { base_uri : 'https://gtmetrix.com', timeout : 10 }
method 'POST'
destination 'api/0.1/test'
options { auth : ['username', 'password'] }

Example Usage

Request

{% set client = {
 base_uri : 'https://gtmetrix.com',
 timeout : 10
} %}

{% set options = {
 auth : ['username', 'password'],
 form_params : {
 url : 'https://www.google.co.uk'
 }
} %}

{% set request = fetch(client, 'POST', 'api/0.1/test', options) %}

Response (successful)

{
 "statusCode":200,
 "reason":"OK",
 "body": {
 "credits_left":30,
 "test_id":"JDHFbrt7",
 "poll_state_url":"https:\/\/gtmetrix.com\/api\/0.1\/test\/JDHFbrt7"
 }
}

You can fetch the string response by adding an additional parameter of false like so:

{% set request = fetch(client, 'POST', 'api/0.1/test', options, false) %}

Response (error)

{
 "error":true,
 "reason":"Client error: `POST https:\/\/gtmetrix.com\/api\/0.1\/test` resulted in a `401 Authorization Required` response:\n{\u0022error\u0022:\u0022Invalid e-mail and\/or API key\u0022}\n\n"
}

Fetch Roadmap

Some things to do, and ideas for potential features:

Brought to you by Luke Youell