{"result":{"depiction_url":null,"edges":{"in_module":{"objects":[{"created":"2020-05-30T05:48:09Z","object_id":{"id":1296,"is_a":["text","documentation","reference","module"],"name":"doc_module_mod_base","title":"mod_base","uri":"https:\/\/zotonic.com\/id\/1296"},"seq":1000000}],"predicate":{"id":333,"is_a":["meta","predicate"],"name":"in_module","title":{"_type":"trans","tr":{"en":"In module"}},"uri":"https:\/\/zotonic.com\/id\/in_module"}},"relation":{"objects":[{"created":"2020-05-30T05:48:09Z","object_id":{"id":1541,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_dispatch_rules","title":{"_type":"trans","tr":{"en":"Dispatch rules"}},"uri":"https:\/\/zotonic.com\/id\/1541"},"seq":1000000},{"created":"2020-05-30T05:48:09Z","object_id":{"id":1540,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_controllers","title":"Controllers","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-09-09T13:47:54Z","object_id":{"id":2555,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_reference","title":"Reference","uri":"https:\/\/zotonic.com\/id\/2555"},"seq":1},{"created":"2026-09-09T13:47:54Z","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-09-09T13:47:54Z","object_id":{"id":2592,"is_a":["categorization","keyword","keyword_domain"],"name":"zotonic_topic_authorization_and_access_control","title":"Authorization and access control","uri":"https:\/\/zotonic.com\/id\/2592"},"seq":3},{"created":"2026-09-09T13:47:54Z","object_id":{"id":2599,"is_a":["categorization","keyword","keyword_domain"],"name":"zotonic_topic_api_and_integration","title":"API and integration","uri":"https:\/\/zotonic.com\/id\/2599"},"seq":4},{"created":"2026-09-09T13:47:54Z","object_id":{"id":2626,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_controller","title":"Controller","uri":"https:\/\/zotonic.com\/id\/2626"},"seq":5},{"created":"2026-09-09T13:47:54Z","object_id":{"id":2676,"is_a":["categorization","keyword","keyword_technology"],"name":"zotonic_topic_http","title":"HTTP","uri":"https:\/\/zotonic.com\/id\/2676"},"seq":6}],"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":1875,"is_a":["text","documentation","reference","controller"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1875"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_controller_controller_api","page_url":{"en":"https:\/\/zotonic.com\/docs\/1875\/controller_api","x-default":"https:\/\/zotonic.com\/docs\/1875\/controller_api"},"preview_url":null,"resource":{"version":3318,"pivot_location_lat":null,"title":"controller_api","is_authoritative":true,"body":"<p><code>controler_api<\/code> processes authorized REST API requests: It provides an easy way to create API calls to allow computer programs to perform functions on your Zotonic site.<\/p>\n<p><code>controller_api<\/code> by default intercepts all URLs according to the patterns <code>\/api\/:topic<\/code>.<\/p>\n<p>The topic can refer to a model. In this case the topic pattern is one of:<\/p>\n<ul><li><code>\/api\/model\/mymodel\/get\/foo\/bar<\/code> maps to <code>m_mymodel:m_get([ &lt;&lt;&quot;foo&quot;&gt;&gt;, &lt;&lt;&quot;bar&quot;&gt;&gt; ], Msg, Context)<\/code><\/li><li><code>\/api\/model\/mymodel\/post\/foo\/bar<\/code> maps to <code>m_mymodel:m_delete([ &lt;&lt;&quot;foo&quot;&gt;&gt;, &lt;&lt;&quot;bar&quot;&gt;&gt; ], Msg, Context)<\/code><\/li><li><code>\/api\/model\/mymodel\/delete\/foo\/bar<\/code> maps to <code>m_mymodel:m_delete([ &lt;&lt;&quot;foo&quot;&gt;&gt;, &lt;&lt;&quot;bar&quot;&gt;&gt; ], Msg, Context)<\/code><\/li><\/ul>\n<p>In all case the <code>Msg<\/code> is an MQTT message map, with the <code>payload<\/code> set to the body of the received request. In case of a\nGET or DELETE the payload is set to a map of the query arguments.<\/p>\n<p>Note that for a POST the payload might not be the complete message as additional query arguments are passed via\n<code>z_context:get_q(&lt;&lt;&quot;argument_name&quot;&gt;&gt;, Context)<\/code>. If the model function is called using MQTT, then all arguments\nare contained in the payload.<\/p>\n<p>The API controller will publish a message to the topic, and wait for max 60 seconds for a response on the response topic.<\/p>\n<p>If there is a query argument <code>response_topic<\/code> then the API controller will only publish the message and immediately return.<\/p>","slug":"controller_api","is_protected":false,"visible_for":0,"tz":"UTC","language":["en"],"doc_source_hash":"a2b1aba877da3489e7d733116f5aee61bbe12cd2310c0ad13b35193fae7beb52","is_featured":false,"content_group_id":{"id":2551,"is_a":["meta","content_group"],"name":"content_group_imported_docs","title":"Imported documentation","uri":"https:\/\/zotonic.com\/id\/content_group_imported_docs"},"category_id":{"id":321,"is_a":["meta","category"],"name":"controller","title":"Controllers","uri":"https:\/\/test.zotonic.com\/id\/321"},"doc_source_path":"apps\/zotonic_mod_base\/src\/controllers\/controller_api.erl","publication_start":"2023-01-30T19:24:02Z","github_url":"https:\/\/github.com\/zotonic\/zotonic\/blob\/master\/apps\/zotonic_mod_base\/src\/controllers\/controller_api.erl","pivot_location_lng":null,"doc_source_kind":"controller","name":"doc_controller_controller_api","is_unfindable":false,"is_published":true,"pivot_geocode":null,"created":"2020-05-30T05:47:41Z","uri":null,"doc_status":"current","is_dependent":false,"erlang_app":"zotonic_mod_base","publication_end":"9999-06-01T00:00:00Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"privacy":0,"doc_source_commit":"85498256abd162b9bc082d43a90c995844fd4408\n","erlang_module":"controller_api","creator_id":{"id":336,"is_a":["person","robot"],"name":"gitbot","title":"Git","uri":"https:\/\/zotonic.com\/id\/336"},"modified":"2026-09-29T14:40:15Z","title_slug":"controller_api"},"uri":"https:\/\/zotonic.com\/id\/1875","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1875"}},"status":"ok"}