api

command module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2021 License: MIT Imports: 32 Imported by: 0

README

API

Build Status codecov Go Report Card GoDoc Sourcegraph Open Source Helpers Release TODOs

What?

Run JSON-API compliant APIs defined using attributes JSON-Schema definitions.

Why?

Quickly run compliant APIs without coding.

How?

  1. sirupsen/logrus for logging.

  2. qri-io/jsonschema for json schema.

  3. viper for command line handling.

  4. cobra for reading configuration.

  5. gin as web framework.

  6. 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.

  1. GET /persons -> 2001, []

  2. GET /persons/{uuid} -> 404

  3. POST /persons { a } -> 201, [ { a } ]

  4. POST /persons { b } -> 201, [ { b } ]

  5. GET /persons?filter=a&sort=a&page=0&limit=100 -> 200, [ a, b ]

  6. GET /persons -> 200, [ a, b ]

  7. GET /persons/{uuid} -> 200

  8. DELETE /persons/{uuid} -> 200

Additional middlewares are enabled as well.

  1. Basic Auth using JWT tokens

  2. OPTIONS

  3. Health probes /liveness /readiness /startup

  4. Logging

  5. Recovery

  6. CORS and CSRF middlewares are enabled

  7. Transaction/Correlation/Revision ID

  8. Rate-limits per Client

  9. 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

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL