Skip to main content

Example 6. Full-fledged CRUD API

JSight API 0.3OpenAPI 3.0.1 (Swagger)
JSIGHT 0.3

GET /cats // Get all cats.
200 [@cat] // Returns all cats.

POST /cats // Create a cat.
Request @cat
200 @cat // Success.

GET /cats/{id} // Get a cat by its id.
200 @cat // Returns a cat.

PUT /cats/{id} // Update a cat.
Request @cat
200 @cat // Returns an updated cat.

DELETE /cats/{id} // Delete a cat.
200 any

TYPE @cat // A cat.
{
"id" : 1,
"name" : "Tom",
"color": "black" // {enum: ["black", "white"]}
}

A full-fledged CRUD API took only 25 lines.

Star us on GitHub — it motivates us a lot!

openapi: 3.0.3
info:
title: ""
version: ""
paths:
/cats:
get:
summary: Get all cats.
responses:
200:
description: ""
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Cat'
post:
summary: Create a cat.
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Cat'
responses:
200:
description: ""
content:
application/json:
schema:
$ref: '#/components/schemas/Cat'
/cats/{id}:
parameters:
- name: id
in: path
required: true
schema: {}
get:
summary: Get a cat by its id.
responses:
200:
description: ""
content:
application/json:
schema:
$ref: '#/components/schemas/Cat'
put:
summary: Update a cat.
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Cat'
responses:
200:
description: ""
content:
application/json:
schema:
$ref: '#/components/schemas/Cat'
delete:
summary: Delete a cat.
responses:
200:
description: ""
content:
application/json:
schema: {}
components:
schemas:
Cat:
description: Type “Cat”.
type: object
required: [id, name, color]
properties:
id:
type: integer
example: 123
name:
type: string
example: "Tom"
color:
type: string
enum: ["black", "white"]