# Response

In ReqEase, handling responses plays a crucial role in ensuring a seamless user experience during web interactions. The response module within ReqEase takes care of managing responses received from HTTP requests. It does this by leveraging various response handlers and callbacks to deliver meaningful feedback to users.

## **Response Handling Process**

Upon receiving a response, the response module follows these steps:

1. **Auto Response Rendering:**
   * If the "autoResponseRender" option is set to `true`, the response module proceeds with rendering the response.
   * If "autoResponseRender" is set to `false`, the response module won't automatically render the response. However, it will still trigger any associated callbacks.
2. **Response Format Validation:**
   * The response module checks if the received response adheres to a known format.
   * If the response format is recognized, the module proceeds with rendering it.
   * If the format is unknown and the "`rejectUnknownResponse`" option is set to `true`, an error is displayed.
   * If "`rejectUnknownResponse`" is set to `false`, the module doesn't render anything for unknown formats.
3.  **Response Type Handling:**

    * The type of response determines how it should be handled.
    * For example, '**MessageResponse**' is handled by '**MessageResponseHandler**,' and '**ProgressResponse**' is managed by '**ProgressResponseHandler**.'
    * These handlers are designed to present responses to users in the most effective and user-friendly manner.



## **Response Types**

ReqEase handles various types of responses to provide an enhanced user experience. These response types help in communicating different kinds of information from the server to the client. Here are some of the key response types in ReqEase:

### **Message Response**

#### **1. Modal Format**

**Modal-Big** and **Modal-Medium** Message Responses: These responses trigger modal dialogs of different sizes. Modal-Big typically presents larger messages, while Modal-Medium displays medium-sized messages.

{% tabs %}
{% tab title="Json" %}
```json
{
    "version": "1.0.0",
    "httpCode": 200,
    
    "type": "modal-big",// or modal-medium
    
    "content": {
        "title": "msg",
        "body": "Hello BOSS!"
    },
    "color": "success",
    "icon": "fas fa-check",
    "buttons": [
        {
            "text": "OK",
            "action": {
                "actionType": "redirect",
                "url": "https://www.example.com/home"
            },
            "color": "success"
        }
    ]
}

```
{% endtab %}

{% tab title="ReqEase-php" %}

{% endtab %}
{% endtabs %}

#### 2. Plain format

**Message-in-Form** and **Message-in-Toast** Message Responses: These responses display messages directly within a form or as toast notifications.



{% tabs %}
{% tab title="json" %}
```json
{
    "version": "1.0.0",
    "httpCode": 200,
    "type": "msg-in-toast",// or msg-in-form
    "content": {
        "title": "msg",
        "body": "Hello BOSS!"
    },
    "color": "warning",
    "icon": "fas fa-check"
}

```
{% endtab %}

{% tab title="ReqEase-php" %}

{% endtab %}
{% endtabs %}

### **Progress Response** <mark style="color:yellow;">**(Coming soon)**</mark>

This response type provides information about the progress of an ongoing operation, including the progress percentage and estimated time left.

### **Data Needed Response&#x20;**<mark style="color:yellow;">**(Coming soon)**</mark>

This response informs the user that additional data is required. It typically prompts the user to provide extra information, such as a password or a captcha, before proceeding.

### **Fields Validation Response**

In cases where backend validation fails, this response type indicates which fields need correction. It's similar to the Form Validator but for backend validation.



{% tabs %}
{% tab title="Json" %}
```json
{
    "version": "1.0.0",
    "httpCode": 200,
    "fieldsWithErrors": {
        "username": ["username is already in use"],
        "email": ["email not allowed"]
    }
}
```
{% endtab %}

{% tab title="ReqEase-php" %}

{% endtab %}
{% endtabs %}

## **Customization and Expansion**

Developers have the flexibility to customize and extend response handling capabilities in ReqEase. This includes modifying existing response handlers, creating new ones, or even adding support for entirely new response types. Such customizations can be tailored to meet the specific needs of your web application.

