From a3675c13336afb0b37e0f211c649813f4f291224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 12 Sep 2023 10:35:37 +0200 Subject: Further doc work. --- doc/ref/web/routes.texi | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 doc/ref/web/routes.texi (limited to 'doc/ref/web/routes.texi') diff --git a/doc/ref/web/routes.texi b/doc/ref/web/routes.texi new file mode 100644 index 00000000..a2249c7a --- /dev/null +++ b/doc/ref/web/routes.texi @@ -0,0 +1,73 @@ +@node HTTP Routes +@section (web http make-routes) + +@defun parse-endpoint-string str +Only really public for tests. +@end defun + +@defmac make-routes routes ... +Expands a number of endpoint specifiers into a procedure suitable for +use as a handler in @xref{Web Server,run-server,run-server,guile}. + +Each form conists of +@itemize +@item the method (``GET'', ``POST'', ...), +@item the path, possibly with embedded parameters, +@item a list of parameters to capture, and +@item the body. +@end itemize + +@example +(make-routes + (GET "/path/:a" (a b) + (return '((content-type text/plain)) + (format #f "a=~a, b=~a" a b))) + ...) +@end example + +The paths can contain embedded variables, which start with +colon, and their name continues until the next slash or period (or end +of string). Each path-embedded parameter must be present in the +parameter list. + +The parameter list must contain all path-embedded parameters, and can +contain any other parameters, which will be bound from the query +parameters, or stay @code{#f} if not supplied by the browser. + +The body should return one to three values, either directly, or +through an early return by calling the procedure @code{return}. + +@defun return headers [body] [new-state] +@end defun + +Inside the body, the following variables are bound to enable producing +the body: + +@defvar request +@defvarx body +The raw request headers and request body. +@end defvar + +@defvar state +The optional state. +@end defvar + +@defvar r:method +@defvarx r:uri +@defvarx r:version +@defvarx r:headers +@defvarx r:meta +The requests components +@end defvar + +@defvar r:scheme +@defvarx r:userinfo +@defvarx r:host +@defvarx r:port +@defvarx r:path +@defvarx r:query +@defvarx r:fragment +The request uri's components. +@end defvar + +@end defmac -- cgit v1.2.3