Experimental project

This is a sandbox project, which contains experimental code for developer use only.

This function is a simple translation for PHP's cURL function into Twig.

Why Might I Need This?
Not every remote web request needs to be manually added in a module or hook. Sometimes, a quick cURL will do, and for when a themer or site builder needs to incorporate remote content in a server-side request rather than an AJAX call, this extension provides the fetch(url, parameters) function to Twig. Default connection timeout is overridden to 30 seconds.

Example usage: {% fetch('http://www.google.com') %}

The optional parameters argument is the value supplied to cURL post fields:
http://php.net/manual/en/function.curl-setopt.php

CURLOPT_POSTFIELDS
The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'. This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. As of PHP 5.2.0, value must be an array if files are passed to this option with the @ prefix. As of PHP 5.5.0, the @ prefix is deprecated and files can be sent using CURLFile. The @ prefix can be disabled for safe passing of values beginning with @ by setting the CURLOPT_SAFE_UPLOAD option to TRUE.

Project information