# File to HTTP

Read a CSV file and send each row to an API.

```ts
// capabilities/file-to-http/route.ts
import { craft, csv, http } from '@routecraft/routecraft'
import { z } from 'zod'

const customer = z.object({
  first_name: z.string(),
  last_name: z.string(),
  email: z.string(),
  status: z.string(),
})

export default craft()
  .id('file-to-http')
  .input({ body: z.array(customer) })
  .from(csv({ path: './customers.csv', header: true }))
  .split()
  .filter(ex => ex.body.status === 'active')
  .transform(row => ({
    name: row.first_name + ' ' + row.last_name,
    email: row.email,
  }))
  .to(http({
    url: 'https://api.example.com/users',
    method: 'POST',
  }))
```

## Input data

**customers.csv:**
```csv
first_name,last_name,email,status
John,Doe,john@test.com,active
Jane,Smith,jane@test.com,inactive
Bob,Wilson,bob@test.com,active
```

## What it does

1. Reads `customers.csv` with headers parsed as object keys
2. Filters to only `active` rows
3. Combines first and last name into a single `name` field
4. POSTs each transformed row to the API

## Result

Two HTTP POST requests, one per active row:

```json
{ "name": "John Doe", "email": "john@test.com" }
{ "name": "Bob Wilson", "email": "bob@test.com" }
```

Jane is skipped because her status is `inactive`.

## Run it

The `csv()` adapter needs its optional peer, `papaparse`:

```bash
bun add papaparse
```

Replace `https://api.example.com/users` with an endpoint you can reach (a local mock or a request-bin service works), save the capability as `capabilities/file-to-http/route.ts` and `customers.csv` in the project root, then start the project from that folder, since the path is resolved against where the process starts:

```bash
bun run start
```

---

## Related

- [csv](/docs/reference/adapters/csv) -- Read and write CSV files: header parsing and every option.
- [http](/docs/reference/adapters/http) -- Serve an endpoint, or call one with a dynamic URL, headers and body.
- [split](/docs/reference/operations/split) -- Turn one exchange carrying a list into one exchange per item.
