> For the complete documentation index, see [llms.txt](https://community-test.logicnets.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://community-test.logicnets.com/release-9/design-considerations-and-frameworks/frameworks/web-services-framework/asynchronous-web-api-calls.md).

# 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) (<https://www.rfc-editor.org/rfc/rfc7240.html#section-4.1>).

Enter *Prefer: respond-async* in the request header.

```
GET /yourcompany/yourapi/endpoint HTTP/1.1
Prefer: respond-async
Authorization: Basic ****
Accept: */*
```

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.

```
HTTP/1.1 202 Accepted
LN-STATUS: 202 Accepted
X-Location: /yourcompany/async.lns?
_asyncid=abc&_session=123&pos=0&stamp=1706792124645
```

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

```
HTTP/1.1 202 Accepted
LN-STATUS: 202 Accepted
X-Location: /logicnets/async.lns?
_session=123&_asyncid=abc&pos=83&stamp=1706797435292
Content-Type: application/json
Content-Length: 105

[{"message":"Processing 1/1000","status":"In progress"},{"message":"Any message","status":"In progress"}]
```

When the background processing is finished the response to the Update request returns HTTP status 200 or an error status when applicable.

```
HTTP/1.1 200 OK
LN-STATUS: 200 OK
Content-Type: application/json
Content-Length: ...

...
```

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

![](https://2802811211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdFhfexCjZ5JMhwGzzywq%2Fuploads%2Fgit-blob-e40f2f9a4c79a402fbfa09bd682bf18f4c0f447d%2Fa7be8ff3-2b34-48be-8fea-79f3e9174ab2.png?alt=media)

## Example

Download the [Asynchronous Web API Calls](/release-9/example-gallery/example-applications/asynchronous-web-api-calls.md) 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://community-test.logicnets.com/release-9/design-considerations-and-frameworks/frameworks/web-services-framework/asynchronous-web-api-calls.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
