From de699dcfb419ab9399e5305006cf575226a794c2 Mon Sep 17 00:00:00 2001 From: Ankit Kumar Date: Fri, 20 Dec 2024 18:55:32 +0530 Subject: [PATCH] quickstart example --- examples/quickstart/README.md | 96 +++++++++++++++++++ examples/quickstart/zillabase/config.yaml | 1 + .../migrations/000000__create_tables.sql | 7 ++ examples/quickstart/zillabase/seed.sql | 4 + 4 files changed, 108 insertions(+) create mode 100644 examples/quickstart/README.md create mode 100644 examples/quickstart/zillabase/config.yaml create mode 100644 examples/quickstart/zillabase/migrations/000000__create_tables.sql create mode 100644 examples/quickstart/zillabase/seed.sql diff --git a/examples/quickstart/README.md b/examples/quickstart/README.md new file mode 100644 index 00000000..f9027b24 --- /dev/null +++ b/examples/quickstart/README.md @@ -0,0 +1,96 @@ +# Zillabase Quickstart + +A quickstart example to get started with Zillabase. + +Both HTTP AsyncAPI 3.x spec & Kafka AsyncAPI 3.x spec are generated automatically based on the Kafka Cluster metadata information. + +#### Install `zillabase` + +```bash +brew tap aklivity/tap + +brew install zillabase +``` + +#### Start `zillabase` stack: + +```bash +zillabase start +``` + +Output: + +```text +3.2.3: Pulling from bitnami/kafka +latest: Pulling from risingwavelabs/risingwave +latest-release: Pulling from apicurio/apicurio-registry-mem +latest: Pulling from bitnami/keycloak +seed-kafka.yaml processed successfully! +Registered AsyncAPI spec: kafka-asyncapi +Registered AsyncAPI spec: http-asyncapi +Config Server is populated with zilla.yaml +``` + +### Using the generated API Endpoints + +The Zillabase quickstart is an HTTP Kafka proxy and exposes common entity CRUD endpoints with the entity data being stored on Kafka topics. Leveraging Kafka's cleanup.policy=compact feature. + +### Endpoints + +| Protocol | Method | Endpoint | Topic | Description | +|----------|--------|--------------|--------|---------------------------------| +| HTTP | POST | /events | events | Create an event. | +| HTTP | PUT | /events/{id} | events | Update an event by the key. | +| HTTP | DELETE | /events/{id} | events | Delete event by the key. | +| HTTP | GET | /events | events | Fetch all events. | +| HTTP | GET | /events/{id} | events | Fetch event by the key. | + + +##### Example: + +##### Publish a valid record + +```bash +curl -k -v -X POST http://localhost:8080/events -H 'Idempotency-Key: 1' -H 'Content-Type: application/json' -d '{"id": "101","message": "Hello, World"}' +``` + +Output: + +```text +> POST /events HTTP/1.1 +... +> Content-Type: application/json +> +< HTTP/1.1 204 No Content +< Access-Control-Allow-Origin: * +< +* Connection #0 to host localhost left intact +``` + +##### Fetch a record + +```bash +curl -k -v http://localhost:8080/events/1 +``` + +Output: + +```text +> GET /events/1 HTTP/1.1 +... +< HTTP/1.1 200 OK +< Content-Length: 33 +< Content-Type: application/json +< Etag: AQIAAg== +< Access-Control-Allow-Origin: * +< Access-Control-Expose-Headers: * +< +* Connection #0 to host localhost left intact +{"id": "101","message": "Hello, World"}% +``` + +#### Stop `zillabase` stack + +```bash +zillabase stop +``` diff --git a/examples/quickstart/zillabase/config.yaml b/examples/quickstart/zillabase/config.yaml new file mode 100644 index 00000000..1417945b --- /dev/null +++ b/examples/quickstart/zillabase/config.yaml @@ -0,0 +1 @@ +# config diff --git a/examples/quickstart/zillabase/migrations/000000__create_tables.sql b/examples/quickstart/zillabase/migrations/000000__create_tables.sql new file mode 100644 index 00000000..f0a7b44a --- /dev/null +++ b/examples/quickstart/zillabase/migrations/000000__create_tables.sql @@ -0,0 +1,7 @@ +-- create_tables + +CREATE ZTABLE events( + id VARCHAR, + message VARCHAR, + PRIMARY KEY (id) +); diff --git a/examples/quickstart/zillabase/seed.sql b/examples/quickstart/zillabase/seed.sql new file mode 100644 index 00000000..fda06109 --- /dev/null +++ b/examples/quickstart/zillabase/seed.sql @@ -0,0 +1,4 @@ +-- seed + +INSERT INTO events (id, message) VALUES ('123', 'Hello'); +INSERT INTO events (id, message) VALUES ('234', 'World');