{
    "href": "/post/2018/12/19/clarifications-to-a-review-of-action-domain-responder/",
    "relId": "2018/12/19/clarifications-to-a-review-of-action-domain-responder",
    "title": "Clarifications to a review of Action Domain Responder",
    "author": "pmjones",
    "markup": "html",
    "tags": [
        {
            "href": "/tag/adr/",
            "relId": "adr",
            "title": "Action Domain Responder",
            "author": null,
            "created": "2020-08-17 21:07:42 UTC",
            "updated": [
                "2020-08-17 21:07:42 UTC",
                "2020-09-22 15:41:16 UTC",
                "2020-10-14 18:20:29 UTC",
                "2020-10-14 18:36:31 UTC",
                "2020-10-14 18:36:53 UTC",
                "2020-10-14 18:37:08 UTC",
                "2020-10-14 18:37:48 UTC",
                "2020-10-14 18:39:26 UTC",
                "2020-10-14 19:03:17 UTC",
                "2020-10-14 19:03:35 UTC",
                "2020-10-26 18:12:53 UTC"
            ],
            "markup": "markdown"
        },
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        },
        {
            "href": "/tag/programming/",
            "relId": "programming",
            "title": "Programming",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        }
    ],
    "created": "2018-12-19 15:30:04 UTC",
    "updated": [
        "2018-12-19 15:30:04 UTC"
    ],
    "html": "<p>Herberto Gra\u00c3\u00a7a, as part of his <a href=\"https://herbertograca.com/2017/07/03/the-software-architecture-chronicles/\">Software Architecture Chronicles</a>, saw fit to review the <a href=\"https://herbertograca.com/2018/09/03/action-domain-responder/\">Action-Domain-Responder</a> pattern that I have written so much about. It\u2019s a good writeup, and you should read the whole thing, but it is off in a couple of places. I sent Herberto a followup email with some minor corrections and clarifications; I repeat it below (with light editing) for posterity.</p>\n<hr>\n<blockquote>\n<p>The ADR pattern was created by Paul M. Jones</p>\n</blockquote>\n<p>I prefer to say, not that I \u201ccreated\u201d the pattern, but that I \u201crecognized and named\u201d it in 2014. <a href=\"http://slimframework.com\">Slim</a>, for example, already had single-action controllers at that time, and the various <a href=\"https://www.martinfowler.com/eaaCatalog/\">Domain Logic</a> patterns previously existed as well. If I \u201ccreated\u201d anything, it was the idea of the Responder; that is, of <a href=\"http://paul-m-jones.com/archives/5993\">treating the Response-building work as a completely separate concern</a>. But even that is just an application of <a href=\"http://martinfowler.com/eaaDev/SeparatedPresentation.html\">Separated Presentation</a>.</p>\n<blockquote>\n<p>to adjust MVC to the context of web REST APIs.</p>\n</blockquote>\n<p>APIs were one aspect, but the origin was more in the typical HTML page-based interface. For example, the word \u201cAction\u201d in Action Domain Responder was inspired both by \u201caction\u201d methods in Controllers, and by the \u201caction\u201d attribute on <code>&lt;form&gt;</code> tags in HTML interfaces.</p>\n<blockquote>\n<p>because the idea is to adapt the MVC pattern to the context of an HTTP REST API, the Action (Controller) names are mapped to the HTTP request methods so we will have Actions with names as Get, Post, Put, Delete</p>\n</blockquote>\n<p>Well, you <em>can</em> do that, but it\u2019s not strictly necessary. I think it would be more accurate to say that it\u2019s typical for an Action to be mapped to a route, and for the routes themselves to be mapped to GET/POST/PUT/DELETE etc.</p>\n<blockquote>\n<p>As an organization pattern, all Actions on a resource should be grouped under a folder named after the resource.</p>\n</blockquote>\n<p>That is one reasonable approach, but it\u2019s not dictated by ADR. Alternatively, instead of grouping Actions by resource, you might organize them by <a href=\"https://infogalactic.com/info/Use_case\">Use Case</a>, or by the intended Interactions with the underlying application.</p>\n<blockquote>\n<p>This pattern was thought of specifically for REST APIs, so in this form it is not refined enough to be used in web applications with an HTML interface (ie. what would be the name of the action to show a form, prior to creating a resource?) \u2026 I think the pattern can easily be extended so that it is fully usable with an HTML interface: We can emulate some extra HTTP methods specifically to handle the HTML requests that a REST API does not have.</p>\n</blockquote>\n<p>Given my notes above, I think it\u2019s fair to say that new HTTP methods are not really needed. What <em>is</em> needed, as Herberto already points out, is a way to \u201cshow a form prior to creating a resource\u201d (among other things).</p>\n<p>Because the Actions do not necessarily map one-to-one with HTTP methods, it\u2019s easy enough to specify that <code>GET /{$resource}/new</code> (or something similar) routes to an Action that gets default values for that resource from the Domain, then hands off to a Responder that builds the form HTML. You can see an example of that here:</p>\n<ul>\n<li>\n<p><a href=\"https://github.com/pmjones/adr-example/blob/master/src/Web/Blog/Add/BlogAddAction.php\">BlogAddAction</a> presents the form with default values</p>\n</li>\n<li>\n<p><a href=\"https://github.com/pmjones/adr-example/blob/master/src/Web/Blog/Create/BlogCreateAction.php\">BlogCreateAction</a> actually creates the resource, or redisplays the form on error.</p>\n</li>\n</ul>\n<p>You might route the first as <code>GET /blog/new</code> and the second as <code>POST /blog</code>. (That idea appears to originate from <a href=\"https://guides.rubyonrails.org/routing.html#crud-verbs-and-actions\">Ruby on Rails</a> and has been imitated elsewhere.)</p>\n<hr>\n<p>Aside from those notes, Herberto\u2019s article is a fair summary and description of ADR. I\u2019m glad he put it together.</p>\n<p>You can read more about Action Domain Responder at <a href=\"http://pmjones.io/adr\">http://pmjones.io/adr</a>.</p>\n"
}
