<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>I would reformat it like this:</p>
    <pre>handleDog: aRequest

    "handle an HTTP request based on its method"

    | id parts |

    aRequest method = 'GET' ifTrue: [ | accept |
        accept := aRequest headerAt: 'Accept'.
        (accept includesSubString: 'application/json') ifTrue: [
            ^self getDogsAsJson: aRequest].

        (accept includesSubString: 'text/html') ifTrue: [
            ^self getDogsAsHtml: aRequest]].

    aRequest method = 'POST' ifTrue: [
        ^self createDog: aRequest].

    "Get the path parameter value."
    "TODO: Is this really the best way to do it?"
    parts := aRequest url prefixAndSuffix: $/.
    id := parts last asNumber.

    aRequest method = 'DELETE' ifTrue: [
        ^self deleteDog: aRequest id: id].

    aRequest method = 'PUT' ifTrue: [
        ^self updateDog: aRequest id: id]

</pre>
    <p></p>
    <p>In my opinion, Smalltalk is not very good for this kind of
      multiple conditions stuff. I know it can be refactored to involve
      and dispatch using several objects, but sometimes (like in this
      case) a multiple conditional solution is fine. In some parts I
      think my code would benefit from having a Lisp/Scheme COND type of
      language construct. Actually, it is easy to implement, but I don't
      use it because it is not part of Cuis Core, the multiple returns
      works for most cases.<br>
    </p>
    <p>     Mariano<br>
    </p>
    <div class="moz-cite-prefix">El 17/6/24 a las 18:20, Mark Volkmann
      via Cuis-dev escribió:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAFfRWnV2P=_nswxBTEZHbMx0i8JOxLe4MStqOwwar+xSH4vLqQ@mail.gmail.com">
      <div><font face="monospace">handleDog: aRequest <br>
              "handle an HTTP request based on its method"<br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><font
          face="monospace">| id parts |<br>
          <br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><font
          face="monospace">aRequest method = 'GET' ifTrue: [<br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">| accept |</span></div>
      <div><font face="monospace"><br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">accept := aRequest headerAt:
          'Accept'.</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">(accept includesSubString:
          'application/json') ifTrue: [</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">self getDogsAsJson: aRequest.</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">^nil</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">].</span></div>
      <div><span style="font-family:monospace"><br>
        </span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">(</span>accept<span
          style="font-family:monospace"> includesSubString: 'text/html')
          ifTrue: [</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">self getDogsAsHtml: aRequest.</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">^nil</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">]</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><font face="monospace">].<br>
          <br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><font
          face="monospace">aRequest method = 'POST' ifTrue: [<br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">self createDog: aRequest.</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">^nil</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><font face="monospace">].<br>
          <br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><font
          face="monospace">"Get the path parameter value."<br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><span
          style="font-family:monospace">"TODO: Is this really the best
          way to do it?"</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><font face="monospace">parts
          := aRequest url prefixAndSuffix: $/.<br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><font
          face="monospace">id := parts last asNumber.<br>
          <br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><font
          face="monospace">aRequest method = 'DELETE' ifTrue: [<br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">self deleteDog: aRequest id: id.</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">^nil</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><font face="monospace">].<br>
          <br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><font
          face="monospace">aRequest method = 'PUT' ifTrue: [<br>
        </font><span style="font-family:monospace">   <span
            class="gmail-Apple-converted-space"> </span></span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">self updateDog: aRequest id: id.</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><span
          style="font-family:monospace">^nil</span></div>
      <div><span style="font-family:monospace">   </span><span
          class="gmail-Apple-converted-space"
          style="font-family:monospace"> </span><font face="monospace">]</font></div>
    </blockquote>
  </body>
</html>