Skip to main content

CRUD API on Kafka


CRUD API on Kafka

Get started with Zilla by deploying our Docker Compose stack. Before proceeding, you should have Docker Composeopen in new window installed.

Running this Zilla sample will create a simple API to create and list items. All of the data will be stored on a Kafka topic.

Setup

Create these files, zilla.yaml and docker-compose.yaml, in the same directory.

zilla.yaml
name: REST-example
bindings:

# Proxy service entrypoint
  north_tcp_server:
    type: tcp
    kind: server
    options:
      host: 0.0.0.0
      port: 7114
    exit: north_http_server
  north_http_server:
    type: http
    kind: server
    routes:
      - when:
          - headers:
              :scheme: http
              :authority: localhost:7114
        exit: north_http_kafka_mapping

# Proxy REST endpoints to Kafka a topic
  north_http_kafka_mapping:
    type: http-kafka
    kind: proxy
    routes:
      - when:
          - method: POST
            path: /items
        exit: north_kafka_cache_client
        with:
          capability: produce
          topic: items-snapshots
      - when:
          - method: GET
            path: /items
        exit: north_kafka_cache_client
        with:
          capability: fetch
          topic: items-snapshots
          merge:
            content-type: application/json

# Kafka sync layer
  north_kafka_cache_client:
    type: kafka
    kind: cache_client
    exit: south_kafka_cache_server
  south_kafka_cache_server:
    type: kafka
    kind: cache_server
    options:
      bootstrap:
        - items-snapshots
    exit: south_kafka_client

# Connect to local Kafka
  south_kafka_client:
    type: kafka
    kind: client
    exit: south_kafka_tcp_client
  south_kafka_tcp_client:
    type: tcp
    kind: client
    options:
      host: ${{env.KAFKA_HOST}}
      port: ${{env.KAFKA_PORT}}
    routes:
      - when:
          - cidr: 0.0.0.0/0




























 



 
 

 



 
 































Run Zilla and Kafka

docker-compose up -d

Use curl to send a greeting

curl -X POST http://localhost:7114/items -H 'Content-Type: application/json' -d '{"greeting":"Hello, world"}'

Use curl to list all of the greetings

curl http://localhost:7114/items
[{"greeting":"Hello, world"}]

Remove the running containers

docker-compose down

See more of what Zilla can do

Go deeper into this concept with the http.kafka.crudopen in new window example.

Going Deeper

Try out more HTTP Kafka examples: