{"result":{"depiction_url":null,"edges":{"hasreference":{"objects":[{"created":"2026-10-07T11:13:39Z","object_id":{"id":1540,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_controllers","title":{"_type":"trans","tr":{"en":"Add an HTTP controller"}},"uri":"https:\/\/zotonic.com\/id\/1540"},"seq":1}],"predicate":{"id":2774,"is_a":["meta","predicate"],"name":"hasreference","title":{"_type":"trans","tr":{"en":"Documentation reference"}},"uri":"https:\/\/zotonic.com\/id\/hasreference"}},"references":{"objects":[{"created":"2021-07-20T12:20:59Z","object_id":{"id":1540,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_controllers","title":{"_type":"trans","tr":{"en":"Add an HTTP controller"}},"uri":"https:\/\/zotonic.com\/id\/1540"},"seq":1000000},{"created":"2021-07-20T12:20:59Z","object_id":{"id":1541,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_dispatch_rules","title":{"_type":"trans","tr":{"en":"Follow a request to its template"}},"uri":"https:\/\/zotonic.com\/id\/1541"},"seq":1000000}],"predicate":{"id":332,"is_a":["meta","predicate"],"name":"references","title":{"_type":"trans","tr":{"en":"References"}},"uri":"https:\/\/zotonic.com\/id\/references"}},"refers":{"objects":[{"created":"2026-10-07T11:13:04Z","object_id":{"id":1537,"is_a":["text","documentation","reference","controller"],"name":"doc_controller_controller_template","title":"controller_template","uri":"https:\/\/zotonic.com\/id\/1537"},"seq":1000000},{"created":"2026-10-07T11:13:04Z","object_id":{"id":1875,"is_a":["text","documentation","reference","controller"],"name":"doc_controller_controller_api","title":"controller_api","uri":"https:\/\/zotonic.com\/id\/1875"},"seq":1000000}],"predicate":{"id":2409,"is_a":["meta","predicate"],"name":"refers","title":{"_type":"trans","tr":{"en":"Refers"}},"uri":"https:\/\/zotonic.com\/id\/refers"}},"relation":{"objects":[{"created":"2021-07-20T12:20:59Z","object_id":{"id":1540,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_controllers","title":{"_type":"trans","tr":{"en":"Add an HTTP controller"}},"uri":"https:\/\/zotonic.com\/id\/1540"},"seq":1000000}],"predicate":{"id":303,"is_a":["meta","predicate"],"name":"relation","title":{"_type":"trans","tr":{"nl":"Relatie","en":"Relation"}},"uri":"http:\/\/purl.org\/dc\/terms\/relation"}},"subject":{"objects":[{"created":"2026-10-07T11:13:39Z","object_id":{"id":2557,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_cookbook_recipe","title":"Cookbook recipe","uri":"https:\/\/zotonic.com\/id\/2557"},"seq":1},{"created":"2026-10-07T11:13:39Z","object_id":{"id":2564,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_backend_developer","title":"Backend developer","uri":"https:\/\/zotonic.com\/id\/2564"},"seq":2},{"created":"2026-10-07T11:13:39Z","object_id":{"id":2626,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_controller","title":"Controller","uri":"https:\/\/zotonic.com\/id\/2626"},"seq":3},{"created":"2026-10-07T11:13:39Z","object_id":{"id":2676,"is_a":["categorization","keyword","keyword_technology"],"name":"zotonic_topic_http","title":"HTTP","uri":"https:\/\/zotonic.com\/id\/2676"},"seq":4}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"id":2259,"is_a":["text","documentation","cookbook"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/2259"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_cookbook_custom_controller","page_url":{"en":"https:\/\/zotonic.com\/cookbook\/2259\/add-an-http-controller","x-default":"https:\/\/zotonic.com\/cookbook\/2259\/add-an-http-controller"},"preview_url":null,"resource":{"body":{"_type":"trans","tr":{"en":"<p>Use <code>controller_template<\/code> for a page that only renders a template. For a public, read-only plain-text endpoint, create <code>src\/controllers\/controller_garden_hello.erl<\/code> in the active Garden application:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">-module(controller_garden_hello).\n-export([content_types_provided\/1, process\/4]).\n\n-spec content_types_provided(Context) -&gt; {Types, Context}\n    when Context :: z:context(), Types :: list().\ncontent_types_provided(Context) -&gt;\n    {[{&lt;&lt;&quot;text&quot;&gt;&gt;, &lt;&lt;&quot;plain&quot;&gt;&gt;, []}], Context}.\n\n-spec process(Method, Accepted, Provided, Context) -&gt; {Body, Context}\n    when Method :: binary(), Accepted :: term(), Provided :: term(),\n         Context :: z:context(), Body :: binary().\nprocess(_Method, _Accepted, _Provided, Context) -&gt;\n    {&lt;&lt;&quot;Welcome to the garden&quot;&gt;&gt;, Context}.\n<\/code><\/pre>\n<p>Add a rule to the application&#39;s <code>priv\/dispatch\/garden<\/code> list:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">{garden_hello, [&quot;garden-hello&quot;], controller_garden_hello, []}\n<\/code><\/pre>\n<p>Compile, refresh discovery, and request <code>\/garden-hello<\/code> on the site&#39;s hostname. Expect a plain-text response containing the greeting. Check dispatch if it returns another page. The rule above is one tuple inside the dispatch list, not an entire dispatch file.<\/p>\n<p>This example deliberately returns public constant text. Private data needs explicit authorization callbacks and model checks; a write endpoint also needs method handling, input validation, and protection against unauthorized requests. Consult <a href=\"\/id\/1537\" class=\"doc-reference doc-reference-controller\"><code>controller#controller_template<\/code><\/a> for a built-in alternative and <a href=\"\/id\/1875\" class=\"doc-reference doc-reference-controller\"><code>controller#controller_api<\/code><\/a> for model-based HTTP access.<\/p>"}},"category_id":{"id":318,"is_a":["meta","category"],"name":"cookbook","title":{"_type":"trans","tr":{"en":"Cookbook"}},"uri":"https:\/\/test.zotonic.com\/id\/318"},"content_group_id":{"id":339,"is_a":["meta","content_group"],"name":"default_content_group","title":{"_type":"trans","tr":{"en":"Default Content Group"}},"uri":"https:\/\/zotonic.com\/id\/default_content_group"},"created":"2021-07-20T12:20:37Z","creator_id":{"id":336,"is_a":["person","robot"],"name":"gitbot","title":"Git","uri":"https:\/\/zotonic.com\/id\/336"},"doc_editorial_bundle":true,"doc_editorial_edges":{"hasreference":[1540],"subject":[2557,2564,2626,2676]},"github_url":"https:\/\/github.com\/zotonic\/zotonic\/tree\/master\/doc\/cookbook\/custom-controller.rst","is_authoritative":true,"is_dependent":false,"is_featured":false,"is_protected":false,"is_published":true,"is_unfindable":false,"language":["en"],"modified":"2026-10-07T11:13:48Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"name":"doc_cookbook_custom_controller","pivot_geocode":null,"pivot_location_lat":null,"pivot_location_lng":null,"privacy":0,"publication_end":"9999-06-01T00:00:00Z","publication_start":"2022-02-15T10:01:39Z","slug":"add-an-http-controller","summary":{"_type":"trans","tr":{"en":"Use controller_template when a dispatch rule only needs to render a template. Write a custom controller when the endpoint needs additional request processing or response behavior."}},"title":{"_type":"trans","tr":{"en":"Add an HTTP controller"}},"title_slug":{"_type":"trans","tr":{"en":"add-an-http-controller"}},"tz":"UTC","uri":null,"version":29,"visible_for":0},"uri":"https:\/\/zotonic.com\/id\/2259","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/2259"}},"status":"ok"}