{"id":13581655,"url":"https://github.com/rehacktive/caffeine","last_synced_at":"2025-05-16T11:06:01.630Z","repository":{"id":45322183,"uuid":"420392988","full_name":"rehacktive/caffeine","owner":"rehacktive","description":"A basic REST service for JSON data - enough for prototyping and MVPs!","archived":false,"fork":false,"pushed_at":"2022-11-30T16:19:55.000Z","size":3280,"stargazers_count":1180,"open_issues_count":0,"forks_count":35,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-09T06:08:39.163Z","etag":null,"topics":["golang","json-api","nosql","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rehacktive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-23T11:26:02.000Z","updated_at":"2025-03-13T23:44:36.000Z","dependencies_parsed_at":"2023-01-22T01:16:00.455Z","dependency_job_id":null,"html_url":"https://github.com/rehacktive/caffeine","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehacktive%2Fcaffeine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehacktive%2Fcaffeine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehacktive%2Fcaffeine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehacktive%2Fcaffeine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rehacktive","download_url":"https://codeload.github.com/rehacktive/caffeine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518383,"owners_count":22084374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","json-api","nosql","rest-api"],"created_at":"2024-08-01T15:02:09.502Z","updated_at":"2025-05-16T11:05:56.621Z","avatar_url":"https://github.com/rehacktive.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# caffeine - minimum viable backend\nA very basic REST service for JSON data - enough for prototyping and MVPs!\n\n**Features**:\n- no need to set up a database, all data is managed automagically*\n- REST paradigm CRUD for multiple entities/namespaces\n- JWT authentication\n- realtime notifications (HTTP/SSE)\n- schema validation\n- autogenerates Swagger/OpenAPI specs\n- search using jq like syntax (see https://stedolan.github.io/jq/manual/)\n- CORS enabled\n- easy to deploy as container\n\n**Currently supports**:\n  - in memory database (map)\n  - sqlite\n  - postgres\n  - filesystem storage\n\nFor a sample Vue app using caffeine see: https://gist.github.com/calogxro/6e601e07c2a937df4418d104fb717570\n\n\n\n## How to\n\nSimply start the server with:\n\n```go \ngo run caffeine.go\n```\noptional params are:\n\n```\nUsage of caffeine:\n  -AUTH_ENABLED=false: enable JWT auth\n  -DB_TYPE=\"memory\": db type to use, options: memory | postgres | fs | sqlite\n  -DB_PATH=\"./data\": path of the file storage root or sqlite database\n  -IP_PORT=\":8000\": ip:port to expose\n  -PG_HOST=\"0.0.0.0\": postgres host (port is 5432)\n  -PG_PASS=\"\": postgres password\n  -PG_USER=\"\": postgres user\n```\n\nStore a new \"user\" with an ID and some json data:\n\n```sh\n\u003e curl -X POST -d '{\"name\":\"jack\",\"age\":25}'  http://localhost:8000/ns/users/1\n{\"name\":\"jack\",\"age\":25}\n```\n\nthe value will be validated, but it could be anything (in JSON!)\n\nretrieve later with:\n\n```sh\n\u003e curl http://localhost:8000/ns/users/1\n{\"name\":\"jack\",\"age\":25}\n```\n\n## All operations\n\nInsert/update\n```sh\n\u003e curl -X POST -d '{\"name\":\"jack\",\"age\":25}'  http://localhost:8000/ns/users/1\n{\"name\":\"jack\",\"age\":25}\n```\n\nDelete\n```sh\n\u003e curl -X DELETE http://localhost:8000/ns/users/1\n```\n\nGet by ID\n```sh\n\u003e curl http://localhost:8000/ns/users/1\n{\"name\":\"jack\",\"age\":25}\n```\n\nGet all values for a namespace\n```sh\n\u003e curl http://localhost:8000/ns/users | jq \n[\n  {\n    \"key\": \"2\",\n    \"value\": {\n      \"age\": 25,\n      \"name\": \"john\"\n    }\n  },\n  {\n    \"key\": \"1\",\n    \"value\": {\n      \"age\": 25,\n      \"name\": \"jack\"\n    }\n  }\n]\n```\n\nGet all namespaces\n```sh\n\u003e curl http://localhost:8000/ns\n[\"users\"]\n```\n\nDelete a namespace\n```sh\n\u003e curl -X DELETE http://localhost:8000/ns/users\n{}\n```\n\nSearch by property (jq syntax)\n```sh\n\u003e curl http://localhost:8000/search/users?filter=\"select(.name==\\\"jack\\\")\"  | jq\n{\n  \"results\": [\n    {\n      \"key\": \"1\",\n      \"value\": {\n        \"age\": 25,\n        \"name\": \"jack\"\n      }\n    }\n  ]\n}\n```\n\n## JWT Authentication \n\nThere's a first implementation of JWT authentication. See [documentation about JWT](JWT.md)\n\n## Realtime Notifications\n\nUsing HTTP Server Sent Events (SSE) you can get notified when data changes, just need to listen from the /broker endpoint:\n\n```sh\ncurl http://localhost:8000/broker\n```\n\nand for every insert or delete an event will be triggered:\n\n```sh\n{\"event\":\"ITEM_ADDED\",\"namespace\":\"test\",\"key\":\"1\",\"value\":{\"name\":\"john\"}}\n...\n{\"event\":\"ITEM_DELETED\",\"namespace\":\"test\",\"key\":\"1\"}\n...\n```\n\n## Swagger/OpenAPI specs\n\nAfter you add some data, you can generate the specs with:\n\n```sh\ncurl -X GET http://localhost:8000/openapi.json\n```\nor you can just go to http://localhost:8000/swaggerui/ and use it interactively!\n\n## Schema Validation\n\nYou can add a schema for a specific namespace, and only correct JSON data will be accepted\n\nTo add a schema for the namespace \"user\", use the one available in schema_sample/:\n\n```sh\ncurl --data-binary @./schema_sample/user_schema.json http://localhost:8000/schema/user\n```\n\nNow only validated \"users\" will be accepted (see user.json and invalid_user.json under schema_sample/)\n\n\n## Run as container\n\n```sh\ndocker build -t caffeine .\n```\nand then run it:\n```sh\ndocker run --publish 8000:8000 caffeine\n```\n\n## Run with Postgres\n\nFirst run an instance of Postgres (for example with docker):\n\n```sh\ndocker run -e POSTGRES_USER=caffeine -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres:latest\n```\n\nThen run caffeine with the right params to connect to the db:\n\n```sh\nDB_TYPE=postgres PG_HOST=0.0.0.0 PG_USER=caffeine PG_PASS=mysecretpassword go run caffeine.go\n```\n\n(params can be passed as ENV variables or as command-line ones)\n\nA very quick to run both on docker with docker-compose:\n\n```sh\ndocker-compose up -d\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehacktive%2Fcaffeine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frehacktive%2Fcaffeine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehacktive%2Fcaffeine/lists"}