Best practices for API wrapper development?

Tom Hukins tom at
Tue May 8 21:22:40 BST 2012

On Tue, May 08, 2012 at 04:52:14PM +0100, Dave Hodgkinson wrote:
> I hated the Amazon one, it was overkill. Probabl my usual approach of
> flinging hashes around is suboptimal. Schwern's position on the shoulders 
> of giants by using DBIC for a relatively simple interface might be too heavy.

It's unclear what you're talking about here.  It would help if you
explained what "Schwern's position" refers to in this case.  No
giggling at the back.

I assume you want to talk to some sort of Web Service API over the
Internet.  I have a few gripes with how several CPAN modules do this
using LWP, most of which I'm occasionally guilty of.

Let your users pass in their own LWP objects if they wish.  This means
they can reuse existing LWP instances, can configure LWP as they wish,
or can pass in an object with a similar interface for testing.

If users don't explicitly pass in an LWP instance, create one with
reasonable defaults.

Enable HTTP persistent connections by setting "keep_alive" to a value
greater than 1.  This particularly helps when using SSL as the client
and server don't need to negotiate an SSL handshake for each request.
When talking to's API using LWP a few years ago, I
found my code ran around 20 times faster with this (from memory: I
might misremember, but it helped lots).

Set "max_redirect" to 0 if you don't expect to receive redirect
responses and restrict the "protocols_allowed" to avoid information
leaking out over protocols you don't want to use.

I don't know whether this answers your question, but I hope it helps.


More information about the mailing list