Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does ApiController require explicit Http verbs on methods?
    primarykey
    data
    text
    <p>I'm using <code>ApiController</code>. I struggle to understand why ApiControllers differ from Controllers in certain ways. </p> <p>Take</p> <pre><code>public class QuestionCommentController : ApiController { QuestionCommentCRUD crud = new QuestionCommentCRUD(); // GET api/questioncomment/5 [HttpGet] public string Read(int id) </code></pre> <p>I'm accustomed to <code>Controller</code> types which allow me to create method without specifying the legal verbs via Attributes:</p> <pre><code>public class QuestionCommentController : Controller { QuestionCommentCRUD crud = new QuestionCommentCRUD(); // GET questioncomment/5 public string Read(int id) </code></pre> <p>In the latter case I can perform GET/POST without specifying <code>HttpGetAttribute</code>. I find this behavior confusing for a few reasons:</p> <ul> <li>There's now two <code>HttpGet</code>: <code>System.Web.Http.HttpGet</code> and <code>System.Web.Mvc.HttpGet</code></li> <li><code>System.Web.Http.HttpGe</code>t is required, <code>System.Web.Mvc.HttpGet</code> is <em>not</em> required for GET requests</li> <li><code>ApiController</code> requests require a unique route <code>/api/controller...</code></li> </ul> <p><code>Controller</code>'s allows me to fall into the pit of success. The newer <code>ApiController</code> requires hand holding. </p> <p>I noticed the default template has a syntax that I don't understand:</p> <pre><code> public void Post([FromBody]string value) { } </code></pre> <p>The verb is the method name along with some funky <code>[FromBody]</code> thing going on. Maybe this is why things are setup this way? What assumptions exist about the usage of <code>ApiController</code> that led to this design? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload