Asynchronous Web API Calls
Description
LogicNets offers the WebServicesFramework to help implement web API services, and the endpoints in packages that use this framework implement web API call processing. This endpoint implementation is modeled as a logicnet.
Used With: This function is used with the WebServicesFramework in LogicNets v8.1+.
Request Header
With web APIs, the endpoint logicnets return a result within a few 100 milliseconds, but processing can take several minutes or even longer—when analyzing big log files, for example. The client needs to wait until the Web API request returns, which can lead to timeouts at the client or infrastructure; for example, the default IIS timeout is 15 minutes and AWS timeout is 1 minute.
To address this, the WebServicesFramework supports asynchronous request handling using RFC 7240: Prefer Header for HTTP (https://www.rfc-editor.org/rfc/rfc7240.html#section-4.1).
Enter Prefer: respond-async in the request header.
The WebServicesFramework detects this header and starts a background processing thread. The initial request is answered with HTTP status 202 Accepted, and the system places a status URL in the X-Location HTTP header. The client uses this to poll for status updates and to collect the result.
Note: The system does not put the redirect location in the “normal” Location header, because some web servers (e.g., IIS) adapt the HTTP status code to 302 and information gets lost.
The system can call the status location URL multiple times, but every response returns an updated URL in the X-Location header. The status request returns HTTP status 202 Accepted while the request is still running and returns detailed status information as part of the response body when available. The detailed status is encoded in a JSON array.
When the background processing is finished the response to the Update request returns HTTP status 200 or an error status when applicable.
Projects based on the WebServicesFramework have a node you can use to report progress. This is in the special dropdown menu and the node is report progress.
Example
Download the Asynchronous Web API Calls example projects that demonstrate the web API asynchronous call functionality:
- Import the AsyncWebAPI project in your workspace and publish it.
- Import the AsyncWebAPITester project and run it.