Requests 2.0 coming soon with proxy support and bug fixes #

Requests logo

The author and maintainers of the popular Requests library are working on a crucial version 2.0 release. As you can see this new release will include a large number of bug fixes and features which are backwards incompatible with the 1.x branch of Requests. Not to worry though, the transition from 1.x to 2.x will be far less painful than the transition from 0.x to 1.x. Most of the backwards incompatibility arises from how 2.x will handle headers (as will be explained below).

Improving HTTPS proxy support

Perhaps the most exciting part of this upcoming release is the improved proxy support. Version 2 will include support for the CONNECT verb which will make talking to HTTPS services possible from behind a proxy. For example: anyone who wishes to use Requests on PythonAnywhere‘s free tier will be able to once version 2 is released. As noted in the pull request, this would not be possible without the amazing work of the contributors to urllib3 — the library on top of which Requests is implemented.

Fixing a subtle bug with headers

Beyond adding proxies, there was a particularly nasty bug on Python 3 where some headers could not be set using native strings. As this was a backwards incompatible change this is only being fixed for the first time in version 2.0. If you have run into this problem your headaches will be long gone.

Adding new convenience methods

Finally, if you are a Requests user who creates their requests carefully by hand, the new method on the Session object will prepare them for you! You no longer have to jump through extra hoops to include the cookies stored on the Session.

Future Requests updates

As soon as Requests 2.0 is out, we will have a full review here, so be sure to subscribe to our Python tag and The Changelog Weekly for further updates.

Weary, Ruby DSL for HTTP goes 1.0, now built on Rack #

Mark Wunsch, whose awesome Tumblr library you might already use, has spent the last few weeks refactoring his Weary project to be fully Rack compatible.

Weary has always sported a rather elegant DSL for wrapping Net::HTTP, but after the big rewrite, you can now use Rack middleware and your client is a Rack application:

# http://developer.github.com/v3/repos/
class GithubRepo < Weary::Client
  domain "https://api.github.com"

  use Rack::Lint

  get :list_user_repos, "/users/{user}/repos" do |resource|
    resource.optional :type
  end

  get :get, "/repos/{user}/{repo}"
end

client = GithubRepo.new
client.list_user_repos(:user => "mwunsch").perform do |response|
  puts response.body if response.success?
end

Check out Mark’s Gilt API wrapper for a complete example of building a wrapper with Weary or the project wiki for more info on how a Weary Request works. Mark has also recorded an introductory screencast that covers what’s new in 1.0:

httpie – Python-powered HTTP CLI for humans #

Although cURL is great, we’re always looking for great console tools for working with HTTP. Jakub Roztocil has released HTTPie. Built on Requests, HTTPie provides a clean command line interface for HTTP requests:

http PATCH api.example.com/person/1 X-API-Token:123 name=John email=john@example.org

PATCH /person/1 HTTP/1.1
User-Agent: HTTPie/0.1
X-API-Token: 123
Content-Type: application/json; charset=utf-8

{"name": "John", "email": "john@example.org"}

I appreciate the colored terminal output:

HTTPie output

Source on GitHub.

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.