Call handler

Purpose: Call another handler within the same process.

 call-handler <request path>

Calls another handler within the same request in the same process. You can call any handler within the same application. "Calling a handler" means executing it solely within the context of the top handler currently running; no before-handler or after-handler will execute for the called handler.

<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.

call-handler uses the same high-performance hash table used by a request to route requests by name; if <request path> is a constant string, then a hash table lookup is performed only once for the life of the process and all subsequent calls use a cached address of the request handler.
Examples
The following example demonstrate calling a call-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.golf":
 %% /callsub public
     //
     // First call to call-handler
     //
     // Set input for call-handler
     set-param inp = "some string"
     (( s
     call-handler "/sub/service"
     ))
     // Get output from call-handler
     get-param out type string
     @<<p-out s>> with output [<<p-out out>>]

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

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

Create and build an application:
gg -k 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  
call-handler  
See all
documentation


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