Framework

- About
- Guides
- Community
- API
- Code
- Download

# Kanso API Documentation

Index | View on single page

## flashmessages

Flash messages help you store state between requests, such as reporting a successful or failed operation after a redirect.

The flash message implementation in this module handles both fallback couchdb mode, using cookies to persist state between requests, as well as supporting client-side operation, correctly handling new messages even inside the callbacks of async functions.

Flash messages only persist for the next request or the next template render! That means 2 redirects without explicitly currying the flash messages will cause the messages to be lost.

### readRequestCookie(req)

Reads the flash messages cookie from a request object, returning an array of incoming messages.

#### Parameters

req | Object |

Returns: Array

### readBrowserCookie()

Reads the flash messages cookie from the browser, returning an array of incoming messages.

Returns: Array

### updateRequest(req)

Adds a flash_messages property to a request containing all incoming messages.

#### Parameters

req | Object |

Returns: Request Object

### getMessages(req)

Get's all current flash messages, stopping them from being outgoing on the next request so they're not repeated.

#### Parameters

req | Object |

Returns: Array

### getOutgoingMessages(req)

Filters all available messages on a request object, returning only those flagged as outgoing (sending in the response to be made available to the next request).

#### Parameters

req | Object |

Returns: Array

### updateResponse(req, res)

Updates a response object after a list, show or update function has returned, setting the flash messages cookie to include the outgoing messages.

#### Parameters

req | Object |
res | Object |

Returns: Response Object

### createMessage(req, msg)

Creates a new flash message object, associating it with the given request.

#### Parameters

req | Object |
msg | String |

Returns: Object

### setBrowserCookie(req, messages)

Stores a list of messages in the flash messages cookie. This function is for client-side use.

#### Parameters

req | Object |
messages | Array |

### addMessage(req, msg)

Adds a new flash message for the current request. If the list, show or update function has not returned, it's added to the response Set-Cookie header, otherwise (if its the result of a client-side async operation) it's added directly to the browsers cookies.

#### Parameters

req | Object |
msg | String |