Examples · examples/echo
echo
The smallest app on the server platform: two endpoints and nothing around them (no +middleware.roc). POST /echo answers with the JSON string it was sent; POST /echo/json reads a nested order into a typed record and writes it back. No browser half: it measures the server itself, and what reading and writing JSON adds.
What it shows#
- Everything a request goes through, and nothing more
- A body read into a nested typed record, and written back
- The server's benchmark, on each endpoint
The benchmark#
Its server, built with --opt=speed as it would ship, under bombardier, which sends a request on each of its connections, the next as soon as the answer is in, for 10 seconds at each number of connections, after a warm-up: first to POST /echo, then to POST /echo/json (examples/echo/bench.sh runs the same). Every request goes through the host, the platform's check that a post isn't from another site's page, the generated routes, reading the JSON body and writing the JSON answer. What differs is the body: a string, then an order that nests.
echo (simple)
Each request is POST /echo with content-type: application/json and the body "hello" (7 bytes): a JSON string, which the endpoint reads into a Str and answers as it is. It's the least an endpoint can be asked, so what's left is the server's own cost.
| Connections | Requests a second | Latency, median | 99th percentile | Errors |
|---|---|---|---|---|
| 1 | 28,160 | 34 µs | 54 µs | 0 |
| 16 | 105,430 | 145 µs | 269 µs | 0 |
| 64 | 123,732 | 492 µs | 976 µs | 0 |
| 256 | 129,134 | 1.9 ms | 3.8 ms | 73 |
Of a request's time, Roc's own (the median of the server-timing its answers carry, one request at a time) is 10 µs: the rest is HTTP and the host.
echo (json)
Each request is POST /echo/json with an order: a customer with an address, items each with its tags, shipping and a note, 725 bytes as sent (compact, as a client sends JSON). The endpoint reads it into a record of its type, Shop.Order (records in records, a list of records, lists of strings, numbers and a Bool), and answers with it, written as JSON again: what most endpoints do with a body. One the type doesn't fit is refused with a 400 before the endpoint runs.
The order it sends
{
"id": "order-1042",
"placed_at": "2026-11-23T19:30:00Z",
"paid": true,
"customer": {
"id": 381,
"name": "Jordan Rivers",
"email": "jordan@example.com",
"address": {
"street": "12 Harbour Lane",
"city": "Bristol",
"postcode": "BS1 4QA",
"country": "GB"
}
},
"items": [
{
"sku": "MUG-BLUE",
"name": "Mug, blue",
"quantity": 2,
"price_cents": 1250,
"tags": [
"kitchen",
"gift"
]
},
{
"sku": "TEA-EARL-250",
"name": "Earl Grey, 250 g",
"quantity": 1,
"price_cents": 899,
"tags": [
"tea",
"loose leaf"
]
},
{
"sku": "CARD-BDAY",
"name": "Birthday card",
"quantity": 3,
"price_cents": 350,
"tags": []
},
{
"sku": "SPOON-WOOD",
"name": "Wooden spoon",
"quantity": 1,
"price_cents": 475,
"tags": [
"kitchen"
]
}
],
"shipping": {
"method": "standard",
"price_cents": 495
},
"notes": "Leave it with the neighbour at number 14"
}| Connections | Requests a second | Latency, median | 99th percentile | Errors |
|---|---|---|---|---|
| 1 | 23,223 | 41 µs | 72 µs | 0 |
| 16 | 94,949 | 162 µs | 295 µs | 0 |
| 64 | 115,086 | 532 µs | 1.0 ms | 0 |
| 256 | 125,211 | 1.9 ms | 4.4 ms | 0 |
Of a request's time, Roc's own (the median of the server-timing its answers carry, one request at a time) is 20 µs (the string's is 10 µs, so reading and writing the order adds 10 µs): the rest is HTTP and the host.
Measured on 2026-11-23, at commit fe4651f, with bombardier on the same machine, competing with the server for its cores: read the numbers as a floor, not a ceiling. The machine's load average went from 2.6 → 12.7 over the run, the benchmark's own load included.
Ran on
- Machine
- MacBook Pro (Mac17,2)
- Processor
- Apple M5 (arm64)
- Cores
- 10 (4 performance, 6 efficiency)
- Memory
- 32 GB
- Storage
- SSD, APFS
- System
- macOS 27.0.1
- Power
- mains
What it's made of#
- Its browser half
- none
- endpoints alone: no wasm
- Pages and endpoints
- 0 + 2
- route files' pages, and handlers
- Lines of Roc
- 42
- its own .roc and .rocx, blank lines left out
- Tests
- 3
- 0 expects, 3 node tests
- Weighs
- no browser half: endpoints alone
- Made of
- 0 pages · 2 endpoints · 42 lines of Roc · 0 expects · 3 node tests
- Uses
- the platform alone
Measured on 2026-11-29 at commit 74eec5b. The wasm is the app's browser half, built with --opt=size; every page also loads start.js, the page's JavaScript, 22.8 KB brotli. All the examples says how they're measured.
Run it#
With the toolchain set up (just setup), start it from its own directory: it builds, serves at http://127.0.0.1:8080 and builds again when you save. Its README says what to look at.
cd examples/echo && ../../bin/rocx devTo build it, check it and run its tests, from the repository's root:
just examples echo
just examples-release echo # as deployed: rocx build, then the tests against a server built --opt=speed