diff mod_rest/mod_rest.lua @ 4488:eea62d30ae08

mod_rest: Add option for serving interactive openapi documentation Swagger not included.
author Kim Alvefur <zash@zash.se>
date Tue, 02 Mar 2021 18:38:13 +0100
parents e453eaf1589e
children 48afaec5d1de
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua	Tue Mar 02 18:35:54 2021 +0100
+++ b/mod_rest/mod_rest.lua	Tue Mar 02 18:38:13 2021 +0100
@@ -309,6 +309,11 @@
 	end
 end
 
+local demo_handlers = {};
+if module:get_option_path("rest_demo_resources", nil) then
+	demo_handlers = module:require"apidemo";
+end
+
 -- Handle stanzas submitted via HTTP
 module:depends("http");
 module:provides("http", {
@@ -316,6 +321,12 @@
 			POST = handle_request;
 			["POST /*"] = handle_request;
 			["GET /*"] = handle_request;
+
+			-- Only if api_demo_resources are set
+			["GET /"] = demo_handlers.redirect;
+			["GET /demo/"] = demo_handlers.main_page;
+			["GET /demo/openapi.yaml"] = demo_handlers.schema;
+			["GET /demo/*"] = demo_handlers.resources;
 		};
 	});