Wynn Netherland changelog.com/posts

Requests - HTTP library for PHP

Higher level libraries for dealing with HTTP are cropping up in almost every language. The latest is Requests, a PHP library from Ryan McCue. Inspired by Kenneth’s Python library of the same name, Requests aims to provide a better HTTP API than cURL:

$headers = array('Accept' => 'application/json');
$options = array('auth' => array('user', 'pass'));
$request = Requests::get('https://api.github.com/gists', $headers, $options);

var_dump($request->status_code);
// int(200)

var_dump($request->headers['content-type']);
// string(31) "application/json; charset=utf-8"

var_dump($request->body);
// string(26891) "[...]"

I’ve written about my thoughts on what makes a good API wrapper and libraries like these that provide a more idiomatic experience are just great.

Grab Requests on GitHub.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00