$Web Api: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<span class="pageSubtitle">Determine whether web API is available</span> This method was first avaliable in Model 204 7.8. <var>$Web_APi</var> indicates whether the current...") |
No edit summary |
||
Line 3: | Line 3: | ||
This method was first avaliable in Model 204 7.8. | This method was first avaliable in Model 204 7.8. | ||
<var>$Web_APi</var> indicates whether the current processing is the result of a request to <var class="product">[[Janus Web Server]]</var>. The difference between $Web_Api and [[$Web]] is that the latter returns 0 on the transactional daemon child (or any transactional descendant) of a web thread whereas the former returns 1, indicating that the $web API is available to the threads. | <var>$Web_APi</var> indicates whether the current processing is the result of a request to <var class="product">[[Janus Web Server]]</var>. The difference between $Web_Api and [[$Web]] is that the latter returns 0 on the [[Daemon class#Transactional_daemons|transactional daemon child]] (or any transactional descendant) of a web thread whereas the former returns 1, indicating that the $web API is available to the threads. | ||
<var>$Web_Api</var> takes no arguments and returns either a 0 or a 1. | <var>$Web_Api</var> takes no arguments and returns either a 0 or a 1. |
Latest revision as of 20:32, 20 January 2020
Determine whether web API is available
This method was first avaliable in Model 204 7.8.
$Web_APi indicates whether the current processing is the result of a request to Janus Web Server. The difference between $Web_Api and $Web is that the latter returns 0 on the transactional daemon child (or any transactional descendant) of a web thread whereas the former returns 1, indicating that the $web API is available to the threads.
$Web_Api takes no arguments and returns either a 0 or a 1.
Syntax
%rc = $Web_Api
Return codes
Code | Meaning |
---|---|
0 | Web API not available. |
1 | Web API available. |
Usage notes
- The $Web function is most useful for:
- Preventing code that should only be run for a web request from running for 3270 (or other non-web) requests.
- Ensuring that non-web, possibly 3270 specific code, is not run for web requests.
- While $web functions are available on transactional daemon descendants of web threads, "terminal" output is not captured to the web output buffer as it is for the web thread itself. If a transactional daemon wishes to add data to the web output buffer it should use $Web_Put_Text or $Web_Put_Bin.
In the example below, the variable %district is set from a form field when running a web request and from a screen field otherwise:
if $web_api then %district = $web_form_parm('DISTRICT') else %district = %query:district end if
- $web_api has several advantages over other techniques for determining whether a request is running a web request, such as checking $Web_Port or doing a
$VIEW('IODEV')
:- It is syntactically simple and easy to understand.
- It works correctly even when a request is being debugged using JANUSDEBUG.
- It works correctly and does not cause a "CONNECTION WAS LOST" user restart after the connection was closed either with a $Web_Done or by the browser. This can be especially useful if there is web-specific processing, like APSY navigation code, that happens after a $Web_Done.