<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;The UI is in pretty good shape.  It&amp;#8217;s time to start hooking this up to a backend.&lt;/p&gt;
&lt;p&gt;Backend needs to support a few basic operations.  We will design this service following &lt;span class=&quot;caps&quot;&gt;REST&lt;/span&gt; principles, so the basic URLs will be as follows (note that actual URLs used by a particular technology may vary, but the essential purpose will be the same:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;GET&lt;/span&gt; /tasks&lt;/strong&gt; &amp;#8211; This request should return all of the tasks defined for the current user.&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;GET&lt;/span&gt; taskURL&lt;/strong&gt; &amp;#8211; Returns the task for a specific &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt;.&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt; /tasks&lt;/strong&gt; &amp;#8211; This request will create a new task, assigning it a unique guid.  It should return a 204 with a Location header for the new record.&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;PUT&lt;/span&gt; taskURL&lt;/strong&gt; &amp;#8211; This request will update the state of a specified task&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;DELETE&lt;/span&gt; taskURL&lt;/strong&gt; &amp;#8211; This request will delete the specified task&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For our design, each task&amp;#8217;s &lt;span class=&quot;caps&quot;&gt;GUID&lt;/span&gt; will be the &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; that it actually belongs to.&lt;/p&gt;
&lt;p&gt;Each request above accepts and posts &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; as its primary payload.  You can easily design services that accept and return multiple formats, but the fastest most convenient format is &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt;.  You can generally design a SproutCore application to work with any backend format that you like.  However, if you follow some standard conventions, it will be easy for the the built-in RestServer to use it.&lt;/p&gt;
&lt;p&gt;Here are the formats:&lt;/p&gt;
&lt;p&gt;Each record is formatted as a simple data hash like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{ guid: &quot;/task/123&quot;,
  title: &quot;Task description&quot;
  isDone: true | false
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For requests that involve a single resource, you could simply pass this data hash, but this would not allow you to pass other meta-data about the resource that might be useful for debugging or other purposes.  Instead, data hashes are usually passed as a content property.  Here is the example format when you retrieve the data for a single task:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
  content: {  
    guid: &quot;/task/123&quot;,
    title: &quot;Task description&quot;,
    order: 1,
    isDone: false
 }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the index request (that returns all of the tasks), the content property is simply an array of data hashes:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
  content: [ 
    { guid: &quot;/task/123&quot;,
      title: &quot;Task description&quot;,
      order: 1,
      isDone: false },

    { guid: &quot;/task/345&quot;,
      title: &quot;Task description&quot;,
      order: 2,
      isDone: false }
   ]
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;SproutCore is backend agnostic.  It can work with any backend server technology that you want to use.  At this point in the tutorial, we are going to play &amp;#8220;choose your own adventure&amp;#8221;.  Depending on the backend technology you want to use you can choose any tutorial listed below.  If a tutorial for your favorite server technology is not listed here, consider following another tutorial and then writing a version for your favorite technology and adding it here.&lt;/p&gt;
&lt;p&gt;We&amp;#8217;re going to start with Merb, because it is installed as part of the SproutCore build tools.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt;[[Building with Merb]]&lt;/strong&gt; (for Merb 0.9.3) &amp;#8211; Merb is a Ruby-based server-side &lt;span class=&quot;caps&quot;&gt;MVC&lt;/span&gt; framework similar to Rails, but smaller and faster.&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;[[Building with Merb 1.0]]&lt;/strong&gt; &amp;#8211; Merb is a Ruby-based server-side &lt;span class=&quot;caps&quot;&gt;MVC&lt;/span&gt; framework similar to Rails, but smaller and faster.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;If you write a tutorial, for your favorite tech here&amp;#8230;first of all, thank you!  Second, please name the starting page &amp;#8220;Building with X&amp;#8221;, where X is your technology and link to it just like the merb example above.  Please keep the list of tutorials above in alphabetical order based on technology name.  Thanks!&lt;/i&gt;&lt;/p&gt;
&lt;h1&gt;Related Links&lt;/h1&gt;
&lt;h1&gt;Comments&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Updated by Daniel Kehoe on 17 January 2009 to add a link to&lt;/em&gt; [[Building with Merb 1.0]]&lt;/p&gt;</body>
  <created-at type="datetime">2008-08-01T20:13:35-07:00</created-at>
  <id type="integer">41823</id>
  <permalink>step-6-building-the-backend</permalink>
  <repository-id type="integer">37005</repository-id>
  <title>Step 6: Building the Backend</title>
  <updated-at type="datetime">2009-04-10T17:08:51-07:00</updated-at>
  <user-id type="integer">20293</user-id>
</wiki>
