Begin handler

Purpose: Define a request handler.

 begin-handler <request path> [ sub-handler ]
     <any code>
 end-handler

begin-handler starts the implementation of a request handler for <request path> (see request), which is <any code> up to end-handler. <request path> is not quoted.

A <request path> can be a request name (i.e. without any forward slashes) or a path consisting of any number of path segments. A request path can have alphanumeric characters, hyphens, underscores and forward slashes, and can start only with an alphabetic character or a forward slash.

For example, a <request path> can be "wine_items" or "/wine-items" "/items/wine" etc. In general, it represents the nature of a request, such as an action on an object, a resource path handled by it etc. There is no specific way to interpret a request path, and you can construct it in a way that works for you.

If "sub-handler" clause is used, then this handler can only be called from another handler by using sub-handler statement; it cannot be called from an outside caller, be it a service call or command-line program. This mechanism automatically guards direct execution by outside callers of such handlers for safety, for instance by checking user credentials first.

Note that you can also use "%%" instead of either begin-handler or end-handler or both.

The source .gliim file name that implements a given begin-handler is a decorated request path, by substituting inner forward slashes with double underscores, and hyphens with a single underscore. For example, <request path> of "/items/wine" would be implemented in  "items__wine.gliim" file.
Examples
The following begin-handler is implemented in file "items__wines__red_wine.gliim":
 begin-handler  /items/wines/red-wine
     @This is a request handler to display a list of red wines!
 end-handler

Another way to write this is:
 %%  /items/wines/red-wine
     @This is a request handler to display a list of red wines!
 %%

See also
Service processing
after-handler  
before-handler  
begin-handler  
sub-handler  
See all
documentation


Copyright (c) 2019-2024 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.