From 0073283f53897d92b07fb832f69c267df9406499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Casper=20K=C3=BCthe?= <43839798+Casper64@users.noreply.github.com> Date: Thu, 20 Jul 2023 01:28:11 +0200 Subject: [PATCH] vweb: add parameter arrays documentation (#18903) --- vlib/vweb/README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/vlib/vweb/README.md b/vlib/vweb/README.md index 2bdc249395..2cb5783f6b 100644 --- a/vlib/vweb/README.md +++ b/vlib/vweb/README.md @@ -234,6 +234,23 @@ header you want example. `app.req.header.get(.content_type)`. See `struct Header for all available methods (`v doc net.http Header`). It has, too, fields for the `query`, `form`, `files`. +#### - Parameter Arrays + +If you want multiple parameters in your route and if you want to parse the parameters +yourself, or you want a wildcard route, you can add `...` after the `:` and name, +e.g. `['/:path...']`. + +This will match all routes after `'/'`. For example the url `/path/to/test` would give +`path = '/path/to/test'`. + +```v ignore + vvv +['/:path...'] vvvv +fn (mut app App) wildcard(path string) vweb.Result { + return app.text('URL path = "${path}"') +} +``` + #### - Query To handle the query context, you just need use the `query` field @@ -500,9 +517,9 @@ pub fn (mut app App) with_auth() bool { } ``` -### Fallback route -You can implement a fallback `not_found` route that is called when a request is made and no -matching route is found. +### Custom not found page +You can implement a `not_found` route that is called when a request is made and no +matching route is found to replace the default HTTP 404 not found page. **Example:**