API
![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/moreandres/api)
What?
Run JSON-API compliant APIs defined using attributes JSON-Schema definitions.
Why?
Quickly run compliant APIs without coding.
How?
-
sirupsen/logrus for logging.
-
qri-io/jsonschema for json schema.
-
viper for command line handling.
-
cobra for reading configuration.
-
gin as web framework.
-
gorm for ORM.
Example
Given persons.json
defined as
{
"type": "object",
"properties": {
"first_name": { "type": "string" },
"last_name": { "type": "string" },
"birthday": { "type": "string", "format": "date" },
"address": {
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" },
"country": { "type" : "string" }
}
}
}
}
The running api run --schema persons.json
will expose a compliant CRUD which can be exercised as below.
-
GET /persons -> 2001, []
-
GET /persons/{uuid} -> 404
-
POST /persons { a } -> 201, [ { a } ]
-
POST /persons { b } -> 201, [ { b } ]
-
GET /persons?filter=a&sort=a&page=0&limit=100 -> 200, [ a, b ]
-
GET /persons -> 200, [ a, b ]
-
GET /persons/{uuid} -> 200
-
DELETE /persons/{uuid} -> 200
Additional middlewares are enabled as well.
-
Basic Auth using JWT tokens
-
OPTIONS
-
Health probes /liveness /readiness /startup
-
Logging
-
Recovery
-
CORS and CSRF middlewares are enabled
-
Transaction/Correlation/Revision ID
-
Rate-limits per Client
-
Stats middleware
Note: Client headers should contain Content-Type: application/vnd.api+json
Design
Config (viper) -> Routes (gin) -> JSON Schema (jsonschema) -> Datbabasabase (Ggrgorm)
Collaborate
sudo apt update
sudo apt upgrade
sudo apt install golang golang-golang-x-tools