Examples
File to HTTP
Read a CSV file and send each row to an API.
import { craft, csv, http } from '@routecraft/routecraft'
export default craft()
.id('file-to-http')
.from(csv({ path: './customers.csv', header: true }))
.filter(row => row.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:
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
- Reads
customers.csvwith headers parsed as object keys - Filters to only
activerows - Combines first and last name into a single
namefield - POSTs each transformed row to the API
Result
Two HTTP POST requests sent to https://api.example.com/users:
{ "name": "John Doe", "email": "john@test.com" }
{ "name": "Bob Wilson", "email": "bob@test.com" }
Jane is skipped because her status is inactive.