# Add CSV Export to a Quarkus REST API

Yes. An agent adds a text/csv export endpoint to a Quarkus Panache resource, with quoting, a download header and REST Assured tests, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-csv-export/quarkus/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the service in its own sandbox before writing a line. In a service like the `hibernate-orm-panache-quickstart` in quarkusio/quarkus-quickstarts, `pom.xml` imports the `quarkus-bom` at platform version 3.40.1.1, depends on `quarkus-hibernate-orm-panache`, `quarkus-rest-jackson` and `quarkus-jdbc-postgresql`, and tests with `quarkus-junit` and `rest-assured` under Surefire 3.5.4; the compiler release is 17 and the project builds with the checked-in `mvnw`. `src/main/resources/application.properties` turns on SQL logging, loads `import.sql` at start, and sets the datasource only under the `%prod` profile, so tests get a Postgres container from Dev Services.

There are two resources that do the same job in two styles. `FruitRepositoryResource` at `repository/fruits` injects a `FruitRepository` that implements `PanacheRepository<Fruit>`; `FruitEntityResource` at `entity/fruits` uses `FruitEntity`, which extends `PanacheEntity`. Both are `@Produces("application/json")` and `@Consumes("application/json")`, list with `listAll(Sort.by("name"))`, and offer `GET {id}`, `POST`, `PUT {id}` and `DELETE {id}` with a nested `ErrorMapper` that turns any exception into a JSON body with `exceptionType`, `code` and `error`. `Fruit` has a generated `Long id` and a `name` column limited to 40 characters and unique. `import.sql` seeds Cherry, Apple and Banana into both tables and resets the sequences. `FruitsEndpointTest` is a `@QuarkusTest` that runs the same list-then-delete check against both paths, and `FruitsEndpointIT` repeats it as a `@QuarkusIntegrationTest`.

The export is added to both resources so the two styles stay parallel. Each gets a `@GET @Path("export") @Produces("text/csv")` method that lists fruits with the same `Sort.by("name")` and returns a `Response` whose entity is the CSV text and whose `Content-Disposition` header is `attachment; filename="fruits.csv"`. The CSV is produced by one small class, `FruitCsv`, in the shared package: a header line `id,name`, one line per fruit, CRLF line endings as the CSV specification uses, and a field quoted with doubled inner quotes whenever it holds a comma, a quote or a line break. No CSV library is added; the format for two columns is a few lines, and keeping the class dependency-free keeps the native profile untouched. Because the class method on `@Produces` is more specific than the class-level JSON, `GET /entity/fruits` keeps answering JSON and `GET /entity/fruits/export` answers CSV.

The tests sit beside the existing one. `FruitsCsvExportTest` is a `@QuarkusTest` that requests both export paths, asserts the status, the `text/csv` content type and the attachment header, and asserts the body starts with the header line and lists Apple, Banana and Cherry in that order, since `import.sql` seeds them and the sort is by name. A second case posts a fruit named with a comma and a quote through the JSON endpoint, exports again and asserts the row is quoted correctly, then deletes it so the other test's expectations hold. A unit test for `FruitCsv` covers the empty list and each quoting rule without starting Quarkus. The agent runs `./mvnw test` in the sandbox, which starts the Dev Services Postgres container, and includes the Surefire summary in the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a CSV export to the fruit resources of this Quarkus service and open a pull request. Read pom.xml, src/main/resources/application.properties, src/main/resources/import.sql, every file under src/main/java and src/test/java, and README.md first. Add GET /repository/fruits/export and GET /entity/fruits/export that produce text/csv with a Content-Disposition attachment header naming fruits.csv, ordered by name like the list endpoints. Write the CSV in a small class with a header line id,name, CRLF line endings, and quoting of fields that contain a comma, a quote or a line break, with no new dependency. Keep the JSON list, get, create, update and delete endpoints and the ErrorMapper unchanged. Add a QuarkusTest that checks both export paths for status, content type, the attachment header, the header line and the seeded fruits in name order, a case that creates a fruit with a comma and a quote in its name and checks the quoting, and a plain unit test for the CSV class. Run ./mvnw test and paste the Surefire summary in the pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch. The diff adds the export method to `FruitRepositoryResource` and `FruitEntityResource`, a `FruitCsv` class in the shared package, `FruitsCsvExportTest` and `FruitCsvTest` under `src/test/java`, and nothing else: `pom.xml`, `application.properties` and `import.sql` are unchanged, which a reviewer can confirm from the file list. The description names the two new paths, shows one `curl` call with its `Content-Type` and `Content-Disposition` headers and the first lines of the body, and pastes the Surefire summary from `./mvnw test`.

The run's full record at `GET /o/{org}/sessions/{id}/messages` keeps the Maven output, including the Dev Services container start and every test class with its result, and `GET /o/{org}/p/{project}/sessions/{id}/changes` returns each file's diff. The quickstarts repository builds pull requests through its own workflow, and the new test class runs there like the existing one.

Before merging, a reviewer checks that the export sorts the same way as the list so the two never disagree, that quoting is applied per field rather than to the whole line, and that the `@Produces("text/csv")` method does not change content negotiation for the JSON routes. Nothing is deployed, and the `%prod` datasource settings are never read in the sandbox.

## Run it on every entity that needs an export

A team that exposes several Panache entities starts one run per resource from the terminal with `POST /o/{org}/sessions`, this prompt with the resource path changed, and the repository in `resources`. Each run reads that resource's fields and sort order, so an entity with a date column gets ISO 8601 values in the CSV and one with a relation gets the related name rather than an id. Each run ends in its own pull request.

Give the API key a `webhook_url` and Rush POSTs `run.completed` when each turn ends, with `session_url` for the pull request link and the pasted test summary. A `request_id` per resource makes a re-run of the script return the run it already started.

## Why run it on Rush?

A CSV endpoint is small, and the mistakes in it are small too: a name with a comma that splits a row, a sort that differs from the list, a content type that trips the JSON writer. Each one is found by running the service against a real database and reading the bytes back. The agent has a sandbox with Docker in it, so `./mvnw test` starts Postgres through Dev Services and the quoting test runs against the real stack rather than a mock.

The pull request shows the headers and the first rows of a real response, the test names say which rules were checked, and the trajectory keeps the Maven output, so a reviewer judges the change from the diff and the record without cloning it.

## Frequently asked questions

### Why not add a CSV library?

Two columns and three quoting rules fit in one class, and the quickstart has a native profile whose build gets slower with each dependency. The class is unit-tested on its own. If your entity has many columns or you already use Jackson's CSV module elsewhere, say so in the prompt and the agent uses `jackson-dataformat-csv` with a `CsvMapper` instead.

### Will Excel open the file correctly?

The export uses CRLF line endings and quotes fields that contain commas, quotes or line breaks, which is what spreadsheet programs expect. A UTF-8 byte order mark is not written by default because it confuses other tools; ask for one in the prompt if your users open the file in Excel on Windows with non-ASCII names.

### Does the export load every row into memory?

For the quickstart's fruit table, yes: `listAll` returns the list and the class writes it to a string. The agent says so in the pull request. For a large table, ask for a `StreamingOutput` that pages through `findAll().page(...)` and writes each page to the response as it goes; the same `FruitCsv` quoting is reused line by line.

### Why both resources?

The quickstart keeps the repository style and the active-record style side by side so readers can compare them, and `FruitsEndpointTest` runs the same checks against both. Adding the export to one would break that symmetry. In an application with a single resource, the agent adds one endpoint.

## More Quarkus jobs

- [Add Cursor Pagination to a Quarkus Panache REST Endpoint](https://getrush.ai/run/add-cursor-pagination/quarkus/)
- [Add Flyway Migrations to a Quarkus App](https://getrush.ai/run/add-flyway-migrations/quarkus/)
- [Add Graceful Shutdown to a Quarkus Service](https://getrush.ai/run/add-graceful-shutdown/quarkus/)

## The same job on other stacks

- [Add a CSV Export to a Symfony Admin Backend from a Linear Issue](https://getrush.ai/run/add-csv-export/symfony/)
- [Add CSV Export to a Wagtail Admin](https://getrush.ai/run/add-csv-export/wagtail/)
- [Add CSV Export to an ASP.NET Core API](https://getrush.ai/run/add-csv-export/aspnet-core/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
