title: REST API + hacks/REST + RPC hybrid. Do I get it right?
body: <p><strong>TL;DR</strong> How to mix REST requests with some non-REST requests in SPA(frontend/backend)? Or might be I just get REST wrong?</p>
  
  <p>We are planning new API for SPA and mobiles(plus probably some 3rd parties). There will be some requests which, I suppose, can't be covered by REST.</p>
  
  <p>I am speaking mostly about requests which would make backend do something, which would modify state of document or give some additional info, based on document, but request itself is rather simplistic.</p>
  
  <p>Here is really easy example. I want to add a comment to blog post. For example I might do it like this:</p>
  
  <ol>
  <li>Create comment. <code>POST /comment</code></li>
  <li>Create connection between author and comment. <code>POST /comment_author</code> or <code>PUT /comment</code> with <code>author_id</code>.</li>
  <li>Create connection between comment and post. <code>POST /comment_post</code> or <code>PUT /comment</code> with <code>post_id</code>.</li>
  </ol>
  
  <p>I also could do something like <code>POST /comment</code> with <code>{author_id, post_id}</code> which actually seems most logical here.</p>
  
  <p>Everything did work, comment added to blogpost and associated with author.</p>
  
  <p>Now customer wants to get statistics for his comment, like words stats and letters stats. As a part of request I pass <code>comment_id</code>. Backend might update comment with stats data, it might create separate entity and link it with comment or it might just send me those stats for this comment without saving.</p>
  
  <p>So what would be the choices? </p>
  
  <p>I can do something like: </p>
  
  <ul>
  <li><code>GET/PUT /comment/:id/stats</code>. For me it seems already hack, because as a result I don't want a document of type comment, but document of different type. As well as I don't send stats with request, I calculate them on backend so using PUT seems wrong.</li>
  <li><code>POST/GET /comment_stats/:comment_id</code>. Seems legit, but if I don't have a document/entity of type comment_stats, that would mean that I actually ask backend to create something, backend would reply me <code>OK/Created</code>, but actually I don't have this document somewhere saved.</li>
  </ul>
  
  <p>So, while I understand REST != CRUD, I thought to use REST for simple CRUD and, for cases like that, to use RPC. So in RPC scenario I would just call <code>POST comment.stats(comment_id)</code></p>
  
  <p>My questions are what would be better choice in this situation, as well as are my thoughts about rest/rpc right?</p>