> For the complete documentation index, see [llms.txt](https://eventrix.gitbook.io/eventrix/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eventrix.gitbook.io/eventrix/receivers/requestshandler.md).

# RequestsHandler

RequestsHandler can handle your requests. You can abort last requests before ended or resolve them. You can do that using methods from RequestsHandler class instance or by emit events from components. This is example how handle request:

{% tabs %}
{% tab title="Javascript" %}

```javascript
import { RequestsHandler, EventsReceiver, Eventrix } from 'eventrix';
import axios from 'axios';

const eventrix = new Eventrix();
const requestsHandler = new RequestsHandler(eventrix);

const fetchUsersReceiver = new EventsReceiver(
    'Users:fetchList',
    (eventName, eventData, stateManager) => {
        const requestId = 'fetchUsers';
        return requestsHandler.handleRequest(
            axios.get('https://abc.com/users'),
            requestId
        ).then(({ data }) => {
            stateManager.setState('users', data);
        });
    }
);

eventrix.useReceiver(fetchUsersReceiver)

export default eventrix;
```

{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}

When you handle request in this way you can abort them by emit event&#x20;

```
emit('AbortRequest:fetchUsers', rejectData)
```

You can also abort last requests using RequestsHandler instance

```javascript
import { RequestsHandler, EventsReceiver, Eventrix } from 'eventrix';
import axios from 'axios';

const eventrix = new Eventrix();
const requestsHandler = new RequestsHandler(eventrix);

const fetchUsersReceiver = new EventsReceiver(
    'Users:fetchList',
    (eventName, eventData, stateManager) => {
        const requestId = 'fetchUsers';
        requestsHandler.abortAllById(requestId, 'request rejected'); // reject last requests
        return requestsHandler.handleRequest(
            axios.get('https://abc.com/users'),
            requestId
        ).then(({ data }) => {
            stateManager.setState('users', data);
        });
    }
);

eventrix.useReceiver(fetchUsersReceiver)

export default eventrix;
```

### **Abort event structure**

&#x20;**"**&#x41;bortRequest:" + **request\_id**

### Resolve event structure

"ResolveRequest:" + **request\_id**

### RequestsHandler instance methods

**abortAll**(rejectData: any) - abort all pending requests

**abortAllById**(requestId: string, responseData: any) - abort all pending requests with requestId

**resolveAll**(rejectData: any) - resolve all pending requests

**resolveAllById**(requestId: string, responseData: any) - resolve all pending requests with requestId

**isAnyPending**(): boolean - check if any request pending

**isPending**(requestId: string): boolean - check if any request pending with requestId


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://eventrix.gitbook.io/eventrix/receivers/requestshandler.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
