Sub handler

Purpose: Call another handler within the same process.

 sub-handler <request path>

Calls another handler within the same request in the same process. You can call any handler within the same application.

<request path> is the request path served by the handler being called. It can be a string variable or a constant.

Use set-param and get-param to pass parameters between the caller and callee handlers.

sub-handler uses the same high-performance hash table used by a request to route requests by name.
Examples
The following example demonstrate calling a sub-handler twice, and also using its output inline in the caller. An input parameter is passed to it, and an output obtained:

Copy to file "callsub.gliim":
 %% /callsub
     //
     // First call to sub-handler
     //
     // Set input for sub-handler
     set-param inp = "some string"
     (( s
     sub-handler "/sub/service"
     ))
     // Get output from sub-handler
     get-param out type string
     @<<p-out s>> with output [<<p-out out>>]

     //
     // Second call to sub-handler
     //
     // Set input for sub-handler called as inline code
     set-param inp = "new string"
     (( s
     @Output: <<sub-handler "/sub/service">>
     ))
     // Get output from sub-handler
     get-param out type string
     @<<p-out s>> with output [<<p-out out>>]
 %%

And in "sub__service.gliim" file:
 %% /sub/service
     @This is sub!
     get-param inp
     (( out
     @got input: <<p-out inp>>
     ))
     set-param out = out
 %%

Create and build an application:
sudo mgrg -i -u $(whoami) subhandler
gg -q

Run it:
gg -r --req="/callsub" --exec --silent-header

The output:
This is sub! with output [got input: some string]
Output: This is sub! with output [got input: new string]

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.