# Response

While Slush automatically converts dictionaries into JSON responses, the `Response` class allows you to customize responses when needed.

## Basic Usage

```python
from slush.core.response import Response

@app.route("/hello", methods=["GET"])
def hello(request):
    return Response(body={"message": "Hello from Slush"}, status=200)
```

## Automatic JSON Responses

You can simply return a dictionary:

```python
@app.route("/hello", methods=["GET"])
def hello(request):
    return {"message": "Hello"}
```

Slush automatically converts it to a JSON response.

## Response Types

### JSON Response

```python
Response.json({"key": "value"})
```

### Text Response

```python
Response.text("Hello world")
```

### HTML Response

```python
Response.html("<h1>Hello</h1>")
```

## Custom Status Codes

```python
Response({"message": "Created"}, status=201)
```

## Setting Headers

```python
res = Response.text("Hello")
res.set_header("X-Custom", "value")
return res
```

## Setting Cookies

```python
res = Response.text("cookie set")
res.set_cookie("session_id", "abc123")
return res
```

## Redirects

```python
return Response.redirect("/hello")
```

## Summary

The `Response` object allows you to:

* Return JSON, text, or HTML
* Set status codes
* Add headers
* Manage cookies
* Redirect requests

## Next Steps

* Add validation using **Pydantic models**


---

# 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://slush.gitbook.io/docs/documentation/basics/response.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.
