# Flash Messages

Sometimes you need to temporarily store data between requests of the same user, such as error or success messages after a form submission. The Iris sessions package supports flash messages.

As we've seen the [Sessions](https://github.com/kataras/iris-book/tree/949c38a02420899aa31dbb029b89f63a3b3846af/sessions/sessions/README.md) chapter, you initialize a session like this:

```go
import "github.com/kataras/iris/v12/sessions"

sess := sessions.New(sessions.Config{Cookie: "cookieName", ...})
```

```go
// [app := iris.New...]

app.Get("/path", func(ctx iris.Context) {
    session := sess.Start(ctx)
    // [...]
})
```

The `Session` contains the following methods to store, retrieve and remove flash messages.

```go
SetFlash(key string, value interface{})
HasFlash() bool
GetFlashes() map[string]interface{}

PeekFlash(key string) interface{}
GetFlash(key string) interface{}
GetFlashString(key string) string
GetFlashStringDefault(key string, defaultValue string) string

DeleteFlash(key string)
ClearFlashes()
```

The method names are self-explained. For example, if you need to get a message and remove it at the next request use the `GetFlash`. When you only need to retrieve but don't remove then use the `PeekFlash`.

> Flash messages are not stored in a database.


---

# Agent Instructions: 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:

```
GET https://iris-go.gitbook.io/iris/contents/sessions/flashmessages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
