title: Questioning the use of DTOs with restful service and extracting behavior from update
body: <p>In the realm of DDD I like the idea of avoiding getters and setters to fully encapsulate a component, so the only interaction that is allowed is the interaction which has been built through behavior.  Combining this with Event Sourcing I can get a nice history of what has been actioned and when to a component.</p>
  
  <p>One thing I have been thinking about is when I want to create, for example, a restful gateway to the underlying service.  For the purposes of example, lets say I have a Task object with the following methods, </p>
  
  <ul>
  <li><code>ChangeDueDate(DateTime date)</code></li>
  <li><code>ChangeDescription(string description)</code></li>
  <li><code>AddTags(params string[] tags)</code></li>
  <li><code>Complete()</code></li>
  </ul>
  
  <p>Now obviously I will have instance variables inside this object for controlling state and events which will be fired when the relevant methods are invoked.</p>
  
  <p>Going back to the REST Service,  the way I see it there are 3 options:</p>
  
  <ol>
  <li>Make RPC style urls e.g. <code>http://127.0.0.1/api/tasks/{taskid}/changeduedate</code></li>
  <li>Allow for many commands to be sent to a single endpoint e.g.:
  
  <ul>
  <li>URL: <code>http://127.0.0.1/api/tasks/{taskid}/commands</code></li>
  <li>This will accept a list of commands so I could send the following in the same request:
  
  <ul>
  <li><code>ChangeDueDate</code> command</li>
  <li><code>ChangeDescription</code> command</li>
  </ul></li>
  </ul></li>
  <li>Make a truly RESTful verb available and I create domain logic to extract changes from a DTO and in turn translate into the relevant events required e.g.:
  
  <ul>
  <li>URL: <code>http://127.0.0.1/api/tasks/{taskid}</code></li>
  <li>I would use the PUT verb to send a DTO representation of a task</li>
  <li>Once received I may give the DTO to the actual Task Domain Object through a method maybe called, UpdateStateFromDto</li>
  <li>This would then analyse the dto and compare the matching properties to its fields to find differences and could have the relevant event which needs to be fired when it finds a difference with a particular property is found.</li>
  </ul></li>
  </ol>
  
  <p>Looking at this now, I feel that the second option looks to be the best but I am wondering what other peoples thoughts on this are, if there is a known true restful way of dealing with this kind of problem.  I know with the second option that it would be a really nice experience from a TDD point of view and also from a performance point of view as I could combine changes in behavior into a single request whilst still tracking change. </p>
  
  <p>The first option would definitely be explicit but would result in more than 1 request if many behaviors needed to be invoked.  </p>
  
  <p>The third option does not sound bad to be but I realise it would require some thougth to come with a clean implementation that could account for different property types, nesting etc...</p>
  
  <p>Thanks for your help in this, really bending my head through analysis paralysis.  Would just like some advice on what others think would be the best way from the options or whether I am missing a trick.</p>