Requests for comment/PHP Virtual REST Service

Problem description
Current PHP bindings to HTTP web services lack some conveniences and features:


 * authentication needs to be performed manually per request rather than being configured per services accessed
 * there is no generic way to load balance or fail over backends to avoid single points of failure
 * multiple requests can't easily be performed in parallel

With more web services in use in the backend infrastructure it might be worth spending some time on optimizing the way we access web services from PHP.

Strawman API design
This is a very early strawman API design that maps fairly easily onto a curl_multi based implementation:

Backend registration
The generic store has a registry of prefixes to storage backends. Matching happens longest-prefix first. Example:

Backends can be HTTP-based, but can also be transparently mapped to local PHP classes or other protocols. The path-based namespace presents a simple and unified API and avoids the need for many different classes. New backend features or backends can be added without a need to upgrade the client bindings. Bulk operations can be performed across several backends.

Tasks to be handled by backend implementations:


 * authentication: retrieve / refresh auth key, add auth headers etc
 * URL and more generally request munging
 * Select form encoding for post requests ( vs  )
 * Accept-encoding default if not specified in request
 * Add Content-MD5 for PUT requests

It should be possible to implement this by passing the full request information to each backend for general munging.

It might be worth considering future support for asynchronous auth key retrieval, even if the initial implementation can be kept simple by doing this synchronously. The key will be cached in the backend object after the first request and will likely not need refresh during a single PHP request.