90 lines
2.2 KiB
Plaintext
90 lines
2.2 KiB
Plaintext
|
package api:todos@1.0.0;
|
||
|
|
||
|
// Common types used across the API
|
||
|
interface types {
|
||
|
// Authentication types derived from OpenAPI security schemes
|
||
|
record bearer-token {
|
||
|
token: string,
|
||
|
}
|
||
|
|
||
|
// Core resource type
|
||
|
record todo {
|
||
|
id: string,
|
||
|
title: string,
|
||
|
description: option<string>,
|
||
|
completed: bool,
|
||
|
due-date: option<string>,
|
||
|
user-id: string,
|
||
|
created-at: string,
|
||
|
updated-at: string,
|
||
|
}
|
||
|
|
||
|
variant error {
|
||
|
unauthorized,
|
||
|
not-found,
|
||
|
validation-error(list<string>),
|
||
|
rate-limited { retry-after: u32 },
|
||
|
server-error,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
interface todos-collection {
|
||
|
use types.{todo, bearer-token, error};
|
||
|
|
||
|
// Request/response types with domain-appropriate fields
|
||
|
record list-request {
|
||
|
auth: bearer-token,
|
||
|
user-id: string,
|
||
|
status: option<string>,
|
||
|
limit: option<u32>,
|
||
|
%offset: option<u32>,
|
||
|
}
|
||
|
|
||
|
record list-response {
|
||
|
items: list<todo>,
|
||
|
total: u32,
|
||
|
limit: u32,
|
||
|
%offset: u32,
|
||
|
version: string, // From ETag
|
||
|
last-updated: option<string>, // From Last-Modified
|
||
|
}
|
||
|
|
||
|
record create-request {
|
||
|
auth: bearer-token,
|
||
|
title: string,
|
||
|
description: option<string>,
|
||
|
due-date: option<string>,
|
||
|
user-id: string,
|
||
|
}
|
||
|
|
||
|
// Note: Response includes versioning info directly in return type
|
||
|
list: func(request: list-request) -> result<list-response, error>;
|
||
|
|
||
|
create: func(request: create-request) -> result<todo, error>;
|
||
|
}
|
||
|
|
||
|
interface todos-resource {
|
||
|
use types.{todo, bearer-token, error};
|
||
|
|
||
|
record update-request {
|
||
|
auth: bearer-token,
|
||
|
title: option<string>,
|
||
|
description: option<string>,
|
||
|
completed: option<bool>,
|
||
|
due-date: option<string>,
|
||
|
expected-version: option<string>, // If-Match header
|
||
|
}
|
||
|
|
||
|
get: func(id: string, auth: bearer-token) -> result<todo, error>;
|
||
|
|
||
|
update: func(id: string, request: update-request) -> result<todo, error>;
|
||
|
|
||
|
delete: func(id: string, auth: bearer-token) -> result<unit, error>;
|
||
|
}
|
||
|
|
||
|
world todos-api {
|
||
|
export todos-collection;
|
||
|
export todos-resource;
|
||
|
}
|
||
|
|