Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
Last active March 6, 2023 11:22
Show Gist options
  • Save kevinswiber/ac0dd7d716ee796cde8329acd3fcdc74 to your computer and use it in GitHub Desktop.
Save kevinswiber/ac0dd7d716ee796cde8329acd3fcdc74 to your computer and use it in GitHub Desktop.
Playing around with an API definition format
package dev.swiber.api.conference
error Error = NotFound | InternalServerError
[location="/conferences"]
resource Conference {
[method="GET", location="/{id}"]
operation Retrieve(RetrieveConference): (ConferenceRetrieved, Error)
[method="POST"]
operation Create(CreateConference): (ConferenceCreated, Error)
}
request RetrieveConference {
location {
parameters {
// description: A unique identifier for a conference.
id {
type "string"
}
}
}
example "Retrieve by ID" {
location {
parameters {
id "total-innovation"
}
}
}
}
request CreateConference {
body {
content-type "application/json"
schema ConferenceSchema
example "Create a new conference" {
body json`{
"address": {
"street": "123 Main St."
}
}`
}
}
}
response ConferenceRetrieved {
status 200
body {
content-type "application/json"
schema ConferenceSchema
example "Retrieve a single conference" {
body json`{
"address": {
"street": "123 Main St."
}
}`
}
}
}
response ConferenceCreated {
status 201
}
response NotFound {
status 404
}
response InternalServerError {
status 500
}
schema ConferenceSchema json`{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"address": {
"type": "object",
"properties": {
"street": {
type: "string"
}
}
}
}
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment