<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Fred Medlin]]></title>
  <link href="http://fredmedlin.com/atom.xml" rel="self"/>
  <link href="http://fredmedlin.com/"/>
  <updated>2012-02-14T14:49:00-05:00</updated>
  <id>http://fredmedlin.com/</id>
  <author>
    <name><![CDATA[Fred Medlin]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Hello, RestClient]]></title>
    <link href="http://fredmedlin.com/blog/2012/02/13/hello-restclient/"/>
    <updated>2012-02-13T20:27:00-05:00</updated>
    <id>http://fredmedlin.com/blog/2012/02/13/hello-restclient</id>
    <content type="html"><![CDATA[<p><a href="https://github.com/fmedlin/RestClient">RestClient</a> is a new Android library project for consuming RESTful api resources. It&#8217;s inspired by the <a href="https://github.com/restkit">RestKit Project</a> but for, you know, Android.</p>

<p>RestClient uses a Builder pattern for object creation that is simple and flexible. Object construction begins with specifying the endpoint of a service api url. There are additional methods for setting the resource, request operation, query parameters, http request parameters, etc.</p>

<p>The execute method starts the network connection with the api service. It runs in the background, so control will return immediately to the calling thread. A completion listener callback is invoked when the operation is complete. It runs in the UI thread, so it is safe to manipulate the UI in the callback methods.</p>

<div><script src='https://gist.github.com/1827657.js?file='></script>
<noscript><pre><code>RestClient.clientWithBaseUrl(&quot;http://gist.github.com/api/v1/&quot;)
    .setResource(&quot;json/1827657&quot;)
    .get()
    .execute(new RestClient.OnCompletionListener() {
        
        public void success(RestClient client, RestResult result) {
            Log(&quot;Successfully retrieved gist&quot;);
            parseGist(result.getResponse());
        }

        public void failedWithError(RestClient restClient, int statusCode, RestResult result) {
        Log(&quot;Error &quot; + statusCode + &quot;, &quot; + result.getResponse());
    }
});
</code></pre></noscript></div>


<p>There is a blocking synchronousExecute() method; handy for those times when you&#8217;re already running in the background and just want to make the api call in the same thread.</p>

<p>I&#8217;ve been gradually refining the library in several commercial projects. This is a new implementation however, replacing
Apache Http classes with HttpURLConnection in order to take advantage of <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">future http work</a> from the Android team.</p>

<p>Documentation is non-existent right now, so your best bet is to refer to the <a href="http://pivotal.github.com/robolectric/">Robolectric</a> based tests.</p>

<p>The next task is to complete the port using HttpURLConnection and beef up the docs and examples. At that point, it should really be production ready. As I said, I&#8217;ve used an Apache based implementation in several apps already and it&#8217;s been pretty solid.</p>
]]></content>
  </entry>
  
</feed>
