Build a REST API in Vectrune
Create a declarative REST API with URL parameters, JSON validation, and generated Swagger documentation in one Rune file.
1. Install and verify
On macOS or Linux with Homebrew, install the CLI and confirm it is available. Windows binaries and source installation are covered in the developer quickstart.
Releases that bundle offline manuals also install man vectrune for CLI commands and man vectrune-language for language/library details through Homebrew. These manuals match the packaged release; the website may describe newer features.
brew install davethomas11/vectrune/vectrune
vectrune --version2. Save this as app.rune
The service uses port 3000. Stop another service using that port, or change the port field and the URLs below.
#!RUNE
@App
name = Greeting API
type = REST
port = 3000
swagger = true
@Schema/Greeting
name = string
enthusiastic = bool
@Route/GET /health
description = Check that the API is running
run:
respond 200 "OK"
@Route/GET /greetings/{name}
description = Read a name from the URL
run:
result = { name: name }
respond 200 result
@Route/POST /greetings
description = Validate and echo a greeting
expect = Greeting
run:
parse-json
validate body #Greeting
respond 201 body
3. Start the service
Run this in the folder containing app.rune. Leave it running and open a second terminal for requests. Stop the server with Ctrl+C when finished.
vectrune app.rune4. Send requests
The health request returns HTTP 200 and OK. The name route returns HTTP 200 with a serialized object containing name = Ada. The POST returns HTTP 201 with the submitted object. The current REST responder serves these bodies as text, including serialized JSON; do not assume an application/json response header.
curl -i http://127.0.0.1:3000/health
curl -i http://127.0.0.1:3000/greetings/Ada
curl -i http://127.0.0.1:3000/greetings -H 'Content-Type: application/json' -d '{"name":"Ada","enthusiastic":true}'5. Try invalid input
This request omits enthusiastic. The server returns HTTP 400 with Missing field `enthusiastic`.
curl -i http://127.0.0.1:3000/greetings -H 'Content-Type: application/json' -d '{"name":"Ada"}'6. Inspect and test
Open http://127.0.0.1:3000/swagger-ui in a browser. Download api.test.rune beside app.rune to run five request tests without starting a separate server.
vectrune test api.test.rune --jsonTest independent apps together
A positional directory loads as a single project. Repeat --app with a directory or entry file for each independent app to keep its constants, routes, and test fixtures separate.
Use --list to see the app-qualified test names or --filter to match names within each suite. JSON output combines the results in one report.
vectrune test --app examples/testing --app examples/language/objects/objects-api.test.rune --jsonPackage a reusable route
Use deps init to create an importable route with a smoke test and a Rune-Web usage guide. Pass --mit-license with the copyright holder if you choose MIT.
vectrune deps init my-addon
cd my-addon
vectrune test tests/smoke.test.rune
vectrune docs/usage.rune -o html > usage.html