Roc Solid
Markup in Roc · pages on a native server · components in WebAssembly

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.

SourceREADMEAll the examples

What it shows#

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
128,16034 µs54 µs0
16105,430145 µs269 µs0
64123,732492 µs976 µs0
256129,1341.9 ms3.8 ms73

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
examples/echo/order.json, laid out (it is sent compact)
{
  "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
123,22341 µs72 µs0
1694,949162 µs295 µs0
64115,086532 µs1.0 ms0
256125,2111.9 ms4.4 ms0

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 dev

To 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