[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/core](../../README) / [index](../README) / ResponseBuilder

# Class: ResponseBuilder

Defined in: [helpers/response.ts:39](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L39)

Fluent builder returned by the redirect helpers for attaching flash data
(`.withErrors()`, `.withSuccess()`, …) to the response.

It implements `PromiseLike<void>` so that `return back().withErrors(...)`
compiles cleanly in handlers typed as `async (ctx): Promise<void>`: TypeScript
unwraps `PromiseLike<void>` in async context, making the builder void-compatible.

## Implements

- `PromiseLike`\<`void`\>

## Constructors

### Constructor

> **new ResponseBuilder**(`ctx`): `ResponseBuilder`

Defined in: [helpers/response.ts:42](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L42)

#### Parameters

##### ctx

[`HttpContext`](HttpContext)

#### Returns

`ResponseBuilder`

## Methods

### with()

> **with**(`key`, `value`): `this`

Defined in: [helpers/response.ts:47](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L47)

Flash an arbitrary key/value onto the next request's session.

#### Parameters

##### key

`string`

##### value

`unknown`

#### Returns

`this`

***

### withErrors()

> **withErrors**(`errors`): `this`

Defined in: [helpers/response.ts:53](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L53)

Flash a map of field errors under the `errors` key.

#### Parameters

##### errors

`Record`\<`string`, `string`\>

#### Returns

`this`

***

### withSuccess()

> **withSuccess**(`message`): `this`

Defined in: [helpers/response.ts:58](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L58)

Flash a success message under the `success` key.

#### Parameters

##### message

`string`

#### Returns

`this`

***

### withError()

> **withError**(`message`): `this`

Defined in: [helpers/response.ts:63](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L63)

Flash an error message under the `error` key.

#### Parameters

##### message

`string`

#### Returns

`this`

***

### withWarning()

> **withWarning**(`message`): `this`

Defined in: [helpers/response.ts:68](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L68)

Flash a warning message under the `warning` key.

#### Parameters

##### message

`string`

#### Returns

`this`

***

### withInfo()

> **withInfo**(`message`): `this`

Defined in: [helpers/response.ts:73](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L73)

Flash an info message under the `info` key.

#### Parameters

##### message

`string`

#### Returns

`this`

***

### then()

> **then**\<`TResult1`, `TResult2`\>(`onfulfilled?`, `onrejected?`): `PromiseLike`\<`TResult1` \| `TResult2`\>

Defined in: [helpers/response.ts:77](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/response.ts#L77)

Attaches callbacks for the resolution and/or rejection of the Promise.

#### Type Parameters

##### TResult1

`TResult1` = `void`

##### TResult2

`TResult2` = `never`

#### Parameters

##### onfulfilled?

((`value`) => `TResult1` \| `PromiseLike`\<`TResult1`\>) \| `null`

The callback to execute when the Promise is resolved.

##### onrejected?

((`reason`) => `TResult2` \| `PromiseLike`\<`TResult2`\>) \| `null`

The callback to execute when the Promise is rejected.

#### Returns

`PromiseLike`\<`TResult1` \| `TResult2`\>

A Promise for the completion of which ever callback is executed.

#### Implementation of

`PromiseLike.then`
