Skip to content

moreandres/api

Repository files navigation

API

API quickly runs JSON-API compliant resources defined by using JSON-Schema attributes definition.

Badges

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

Usage

docker build -t my-api .
docker run -p 8080:8080 -it --rm --name my-running-api my-api

Details

API will expose a compliant resource data including:

  1. Creating
POST /v1/resource
  1. Fetching
GET /v1/resource
GET /v1/resource?sort=-id&page=0&limit=10
GET /v1/resource/{id}
  1. Updating
PATCH /v1/resource/{id}
  1. Deleting
DELETE /v1/resource/{id}

API will also expose supporting resources for health check and profiling

  1. Health
GET /v1/health
  1. Profiling
GET /debug/pprof

API adds middleware to:

  1. Failover from failures
  2. Include service revision
  3. Limit concurrent connections
  4. Include basic security controls
  5. Restrict access
  6. Keep usage statistics
  7. Avoid CORS issues
  8. Support compression
  9. Include request ID

Check API tests for further usage details.

Configuration

API uses API_XXX environment variables or configuration files

  1. LogLevel (Info)
  2. SchemaName (objects.json)
  3. DbUri (file::memory:?cache=shared)
  4. HttpPort (8080)
  5. UseSSL (false)
  6. HttpsPort (8443)
  7. CertFile (api.cer)
  8. KeyFile (api.key)
  9. URL
  10. QueryLimit (512)
  11. JwtSecret (password)
  12. MaxAllowed (20)
  13. AccessCidr (0.0.0.0/0)

Implementation

API uses:

  1. sirupsen/logrus for logging.
  2. qri-io/jsonschema for JSON-Schema validation.
  3. cobra for reading configuration from environment and configuration files.
  4. gin as web framework to expose resources.
  5. gorm for ORM to store and retrieve data.

Deployment

API can be deployed using classic infrastructure. CloudWatch metrics and logs are enabled. Session Manager can be used to SSH into instances.

terraform init
terraform apply
terraform destroy

Windows Development

  1. Enable WSL 2
  2. Install chocolatey
  3. Install tooling
choco install git git-lfs github-desktop docker-desktop golang mingw packer terraform vscode python minikube vagrant virtualbox

About

JSON-API compliant APIs from JSON-Schema attributes definition

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published