On Oct 6, 6:58 pm, Hans Hübner <[EMAIL PROTECTED]> wrote:
> The API I am working with is xlightweb, an asynchronous HTTP client/
> server framework based on xSocket.  API docs are 
> athttp://xlightweb.sourceforge.net/core/apidocs/2_1/
>
> Any thoughts would be greatly appreciated.

I've been thinking about this, and I think I have a few points of
advice to give.

The most important thing I can think of is to remember that your
wrapper doesn't have to be comprehensive. Clojure has various
functions in the standard library to handle regular expressions, but
they don't attempt to be a complete replacement for working with
Pattern and Matcher objects. Falling back to Java classes is okay for
complex and unusual cases.

So keep it simple, and write wrappers for the common use-cases. Try to
stay functional, and take full advantage of all the standard Clojure
data structures, the Clojure standard library, and of first class
functions and macros.

For instance, here's a cut down version of some example code from the
xlightweb docs:

   HttpClient httpClient = new HttpClient();

   IHttpResponse response = httpClient.call(new GetRequest("http://
www.gmx.com/index.html"));
   System.out.println(response.getStatus());

   BlockingBodyDataSource bodyChannel = response.getBlockingBody();
   System.out.println(bodyChannel.readString());

   httpClient.send(new HttpRequestHeader("GET", "http://www.gmx.com/
index.html"), respHdl);

   httpClient.close();

A more Clojure-like way of writing it might be:

  (with-open client (new HttpClient)
    (let [response (get-url client "http://www.gmx.com/index.html";)]
      (.printLn *out* (read-body response)))
    (get-url client "http://www.gmx.com/index.html"; handler-function))

Although, since this is HTTP, you're not actually keeping any
connections open, unless they happen to belong to the same domain. So
maybe you could cut out the client altogether, by generating a new one
each time:

  (let [response (get-url "http://www.gmx.com/index.html";)]
    (.printLn *out* (read-body response)))
  (get-url "http://www.gmx.com/index.html"; handler-function))

Really, it depends what you think you'll be using the library for most
often, and what other people will want to do. Maybe most of the time
all people want is the body of the HttpResponse, so:

  (.printLn *out* (read-url "http://www.gmx.com/index.html";))

So long as people can go back and use the Java API to do the complex
stuff, I figure the best way to approach wrapper libraries is to make
it as easy and as straightforward as possible for people to start
using it.

- James
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to