-
Notifications
You must be signed in to change notification settings - Fork 0
Guide HTTP Services
ARO provides built-in HTTP server capabilities using a contract-first approach. Routes are defined in an OpenAPI specification, and ARO feature sets handle the requests.
ARO uses OpenAPI contracts to define HTTP routes. The HTTP server automatically starts when a contract file is present in your application directory. The runtime looks for files in this precedence order: openapi.yaml, openapi.yml, openapi.json.
Key Principles:
- Routes are defined in your OpenAPI contract, not in ARO code
- Feature set names must match
operationIdvalues from the contract - No HTTP server without a contract (no OpenAPI file = no server)
MyAPI/
├── openapi.yaml # Required: Defines all HTTP routes
├── main.aro # Application-Start with Keepalive
└── handlers.aro # Feature sets matching operationIds
openapi: 3.0.3
info:
title: User API
version: 1.0.0
paths:
/users:
get:
operationId: listUsers # Feature set name in ARO
responses:
'200':
description: Success
post:
operationId: createUser # Feature set name in ARO
responses:
'201':
description: Created
/users/{id}:
get:
operationId: getUser # Feature set name in ARO
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: SuccessFeature sets must be named after the operationId from your OpenAPI contract:
(* Feature set name = operationId from openapi.yaml *)
(listUsers: User API) {
<Retrieve> the <users> from the <user-repository>.
<Return> an <OK: status> with <users>.
}
(createUser: User API) {
<Extract> the <data> from the <request: body>.
<Create> the <user> with <data>.
<Store> the <user> into the <user-repository>.
<Return> a <Created: status> with <user>.
}
(getUser: User API) {
<Extract> the <id> from the <pathParameters: id>.
<Retrieve> the <user> from the <user-repository> where id = <id>.
<Return> an <OK: status> with <user>.
}
The HTTP server starts automatically. Use <Keepalive> to keep the application running:
(Application-Start: User API) {
<Log> "User API starting..." to the <console>.
<Keepalive> the <application> for the <events>.
<Return> an <OK: status> for the <startup>.
}
<Extract> the <user-id> from the <pathParameters: id>.
<Extract> the <page> from the <queryParameters: page>.
<Extract> the <data> from the <request: body>.
<Extract> the <auth-token> from the <request: headers.Authorization>.
(* 2xx Success *)
<Return> an <OK: status> with <data>. (* 200 *)
<Return> a <Created: status> with <resource>. (* 201 *)
<Return> a <NoContent: status> for <deletion>. (* 204 *)
(* 4xx Client Errors *)
<Return> a <BadRequest: status> with <errors>. (* 400 *)
<Return> an <Unauthorized: status> for <auth>. (* 401 *)
<Return> a <Forbidden: status> for <access>. (* 403 *)
<Return> a <NotFound: status> for <missing>. (* 404 *)
(* 5xx Server Errors *)
<Return> an <InternalError: status> for <error>. (* 500 *)
For making outgoing HTTP requests, use the <Request> action:
<Request> the <data> from "https://api.example.com/resource".
For more details on HTTP client functionality including configuration objects, headers, and POST/PUT requests, see HTTP Client.
- File System - File operations and monitoring
- Sockets - TCP communication
- Events - Event-driven patterns
Fundamentals
- The Basics
- Feature Sets
- Actions
- Variables
- Type System
- Control Flow
- Error Handling
- Computations
- Dates
- Concurrency
Runtime & Events
I/O & Communication
Advanced