Last active
March 6, 2023 11:22
-
-
Save kevinswiber/ac0dd7d716ee796cde8329acd3fcdc74 to your computer and use it in GitHub Desktop.
Playing around with an API definition format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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