# Events

Hooks are functions that are called after an event.

Let's suppose you want to add a header to every response in your app. Instead of manually editing every single route in your app you can just register a listener to the event "BeforeResponse" and inject the desired headers.

Below is a fully working example:

```python
from vibora import Vibora, Response
from vibora.hooks import Events

app = Vibora()

@app.route('/')
async def home():
    return Response(b'Hello World')

@app.handle(Events.BEFORE_RESPONSE)
async def before_response(response: Response):
    response.headers['x-my-custom-header'] = 'Hello :)'

if __name__ == '__main__':
    app.run()
```

Hooks can halt a request and prevent a route from being called, completely modify the response, handle app start/stop functionalities, initialize components and do all kind of stuff.

> The golden rule is: If you don't want to modify the request flow (like halting requests) you don't want to return anything in your function. Of course that depends on which event you are listening to.


---

# 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://docs.vibora.io/events.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.
