A simple Go HTTP API server that allowes to store and access JSON decoments with predefined document schema.
QuickStore can be used to run a small server for storing web form submissions, or to collect user feedback about a product in a structured JSON format.
-
clone this repo.
-
rename
config.example.jsontoconfig.jsonand update the contents according to your needs. -
Run
go run .The server will start on http://localhost:8080 as specified in config.json.
You can override the config and database paths:
go run . -config ./config.json -db ./quickstore.dbQuickStore reads config.json at startup and validates it against the JSON Schema in config_schema.go.
Example:
{
"host": "localhost",
"port": 8080,
"access_tokens": [
{ "name": "public", "token": "public_access_token" }
{ "name": "private", "token": "private_access_token" }
],
"collections": [
{
"name": "products",
"auth": {
"all": ["private"],
"create": [],
"read": ["public"],
"list": ["public"],
"replace": [],
"patch": [],
"delete": []
},
"schema": {
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"productId": {
"description": "The unique identifier for a product",
"type": "integer"
},
"productName": {
"description": "Name of the product",
"type": "string"
}
},
"required": ["productId","productName"],
"additionalProperties": false
}
}
]
}Field usage:
host: Hostname or IP address the server binds to.port: TCP port the server listens on.access_tokens: List of access tokens that can authenticate requests.access_tokens[].name: Friendly label used by collection auth rules.access_tokens[].token: Secret bearer token value.collections: List of collection definitions.collections[].name: Collection name used in API routes.collections[].auth: Per-action access control lists.collections[].auth.all: Tokens allowed to perform any action.collections[].auth.create: Tokens allowed to create records.collections[].auth.read: Tokens allowed to read a single record.collections[].auth.list: Tokens allowed to list records.collections[].auth.replace: Tokens allowed to replace a record.collections[].auth.patch: Tokens allowed to partially update a record.collections[].auth.delete: Tokens allowed to delete a record.collections[].schema: JSON Schema of the collection document.
GET /api/health- Health check endpointGET /api/{collection}- Get all documents from a collectionPOST /api/{collection}- Insert a new document into a collectionGET /api/{collection}/{id}- Get a document by IDPUT /api/{collection}/{id}- Replace a documentDELETE /api/{collection}/{id}- Delete a document
http://localhost:8080/docs/ - Swagger UI
http://localhost:8080/docs/apispec.json - OpenAPI Spec JSON
curl http://localhost:8080/api/healthExpected response:
{"message": "OK"}Build in debug mode
go build -o quickstore
./quickstoreBuild in release mode
go build -o quickstore -ldflags="-s -w"go.mod- Go module definitionmain.go- Main server file with the server setup and routingconfig.go- Configuration handlingdb.go- Database operationsroutes.go- HTTP route handlersoapi.go- OpenAPI/Swagger specificationREADME.md- This file