title: HATEOAS POST link in HAL
body: <p>How do I describe POST links in HAL?</p>
  <p>I'm designing a RESTful API with HATEOAS constraints, similar to <a href="https://en.wikipedia.org/wiki/HATEOAS" rel="nofollow noreferrer">Wikipedia's HATEOAS example</a> but expressed in HAL JSON (dropping the scheme, host, etc. for clarity):</p>
  <pre><code>GET /accounts/12345
  
  {
    &quot;id&quot; : 12345,
    &quot;balance&quot; : 100.00
    &quot;_links&quot; : {
      &quot;self&quot; : {
        &quot;href&quot; : &quot;/accounts/12345&quot;
      },
      &quot;transfer&quot; : {
        &quot;href&quot; : &quot;/accounts/12345/transfer{?amount,target}&quot;,
        &quot;templated&quot; : true
      }
    }
  }
  </code></pre>
  <p>To perform the &quot;transfer&quot; action, the client would presumably do:</p>
  <pre><code>GET /accounts/12345/transfer?amount=100.00,target=54321
  
  {
    &quot;id&quot; : 34567,
    &quot;amount&quot; : 100.00
    &quot;_links&quot; : {
      &quot;self&quot; : {
        &quot;href&quot; : &quot;/transfers/34567&quot;
      },
      &quot;source&quot; : {
        &quot;href&quot; : &quot;/account/12345&quot;
      },
      &quot;target&quot; : {
        &quot;href&quot; : &quot;/account/54321&quot;
      }
    }
  }
  </code></pre>
  <p>Invoking the &quot;transfer&quot; link via GET creates a new ressource in &quot;transfers&quot;. But doing a GET to create a new resource is not idempotent and it &quot;feels&quot; wrong; a RESTful resource centric API would POST:</p>
  <pre><code>POST {amount: 10.00, source: 12345, target: 54321}  /transfers/
  
  {
    &quot;id&quot; : 34567,
    &quot;amount&quot; : 100.00
    &quot;_links&quot; : {
      &quot;self&quot; : {
        &quot;href&quot; : &quot;/transfers/34567&quot;
      },
      &quot;source&quot; : {
        &quot;href&quot; : &quot;/account/12345&quot;
      },
      &quot;target&quot; : {
        &quot;href&quot; : &quot;/account/54321&quot;
      }
    }
  }
  </code></pre>
  <p>But how do I describe this POST and the required form elements in HAL so the client can just do the &quot;Right Thing&quot; without being hard-coded? Perhaps something like:</p>
  <pre><code>{
    &quot;id&quot; : 12345,
    &quot;balance&quot; : 100.00
    &quot;_links&quot; : {
      &quot;self&quot; : {
        &quot;href&quot; : &quot;/accounts/12345&quot;
      },
      &quot;transfer&quot; : {
        &quot;href&quot; : &quot;/transfers{?amount,source,target}&quot;,
        &quot;templated&quot; : true,
        &quot;method&quot; : &quot;POST&quot;
      }
    }
  }
  </code></pre>
  <p>But <code>method</code> not part of the <a href="https://datatracker.ietf.org/doc/html/draft-kelly-json-hal-08" rel="nofollow noreferrer">HAL specification</a> and there's no analogous identifier -- so it feels like I'm on the wrong track...</p>
  <p>Perhaps my client should just &quot;know&quot; that a GET of <code>transfer</code> returns matching transfer resources, and a POST to <code>transfer</code> creates a new transfer resource.</p>
  <p>FWIW, my implementation uses Spring Boot 2 with Spring HATEOAS so the follow-up question is how to express this with Spring HATEOAS...</p>