Get started Browse docs
On this page 6 sections

Get started

Your first service

Build a web service from one 20-line file, run it, and check it with curl. You end with a server answering on port 8080.

By the end of this page a web service is running on your machine, and this command returns JSON:

The check you will run
curl http://127.0.0.1:8080/health

You need a built compiler first: see install the compiler. The service is health_service.orb from the repository’s examples/ folder. It uses no database, so there is nothing to configure, no tables to seed, and no sqlite3.dll to copy on Windows.

The service

The whole file is twenty lines. A route is a URL path plus an HTTP method that the service answers. This file has three routes, and each one reads live runtime counters:

examples/health_service.orb
// Production Health & Observability Service example in Orbit.
// Provides health probes, readiness probes, and metrics endpoints.
// Every value below comes from live runtime counters (see system.* in
// the language reference). What is not measured is not exposed.

route GET "/health" {
  val uptime = system.uptime()
  return ok 200 """{"status":"UP","version":"0.1.0","uptime_seconds":${uptime}}"""
}

route GET "/ready" {
  return ok 200 """{"ready":true,"accepting_traffic":true}"""
}

route GET "/metrics" {
  val total = system.http_requests_total()
  val latency = system.latency_avg_us()
  val workers = system.active_workers()
  return ok 200 """{"metrics":{"http_requests_total":${total},"latency_avg_us":${latency},"active_workers":${workers}}}"""
}

What each part does:

  • route GET "/health" answers GET /health. system.uptime() returns the seconds since the server started, and ${uptime} puts that number into the JSON text.
  • return ok 200 """...""" sends status 200 with the text between the triple quotes as the response body.
  • route GET "/ready" returns a fixed body. A load balancer asks this route whether the service can take traffic.
  • route GET "/metrics" reads three counters: system.http_requests_total(), system.latency_avg_us() and system.active_workers(). It puts each one into the JSON.

Build it

One file in, one native binary out. This is the same orbit build you used in your first program, with one added flag. The service declares routes. The native R6 backend refuses every routed program, so the build passes --backend=c:

PowerShell
.orbit.exe build examples/health_service.orb --backend=c -o health_service.exe

Run it

Pass the port as the first argument. This starts the server on 8080. With no argument it listens on the default, 3000:

PowerShell
.health_service.exe 8080

The binary stays in the foreground and serves until you stop it. Leave that terminal open and use a second terminal for everything below.

Check health

From the second terminal, ask the service for its health:

Check
curl http://127.0.0.1:8080/health
Response
{"status":"UP","version":"0.1.0","uptime_seconds":0}

Your Orbit service answered. The body has three fields: status is UP, version is the fixed example tag, and uptime_seconds is measured by system.uptime(). It reads 0 because you just started the server. Run the check again a few seconds later and the number grows.

Try GET /ready too. It answers {"ready":true,"accepting_traffic":true}, the shape a load balancer’s readiness probe expects:

Check
curl http://127.0.0.1:8080/ready

Metrics and ledger

Two more endpoints come with every service. You write no instrumentation code for them:

  • GET /metrics returns request count, average latency and active workers, from the same system.* counters the example reads.
  • GET /_ledger returns a per-route table: requests, mean latency and database share. The ledger is the runtime’s own record, and it keeps it whether or not your program mentions it.

The language tour shows both with real numbers.

Stop it

Press Ctrl-C in the server’s terminal. That is the whole shutdown: there is no daemon to unregister and no container to remove.

What next

A service that answers health checks is a start. Next, values and types begins the language itself; when you want to see the counters and per-route costs this service already collects, read observability. If the port is busy, see troubleshooting.

Type to search commands, errors, modules and concepts.