rmoff's random ramblings
about talks

KSQL REST API cheatsheet

Published Jan 17, 2019 by in KsqlDB, Rest at https://rmoff.net/2019/01/17/ksql-rest-api-cheatsheet/

Full reference is here

Note
The REST API has two different endpoints: ksql and query - make sure you use the correct one. If you don’t you’ll run into problems and errors like Statement type `io.confluent.ksql.parser.tree.CreateStream' not supported for this resource.
  • Run a query

    $ curl -X POST \
        http://localhost:8088/query \
        -H 'content-type: application/vnd.ksql.v1+json; charset=utf-8' \
        -d '{"ksql":"SELECT * FROM COMPUTER_T;", "streamsProperties": {
          "ksql.streams.auto.offset.reset": "earliest"
        }}'
    
    
    {"row":{"columns":[1547723561637,"100",1,"100","e0:a1:d7:18:c2:72"]},"errorMessage":null,"finalMessage":null}
    {"row":{"columns":[1547723561637,"101",2,"101","e1:a3:d7:18:c2:72"]},"errorMessage":null,"finalMessage":null}
    {"row":{"columns":[1547723561637,"102",3,"102","e2:a4:d7:18:c2:72"]},"errorMessage":null,"finalMessage":null}

    Remember, KSQL is a continuous query so this will keep executing; use LIMIT x if you just want the first x rows.

  • Run a statement, use jq to format the output

    $ curl -s -X POST \
           http://localhost:8088/ksql \
           -H "Content-Type: application/vnd.ksql.v1+json; charset=utf-8" \
           -d '{
                  "ksql": "LIST TABLES;"
                }'| jq '.'
    [
      {
        "@type": "tables",
        "statementText": "LIST TABLES;",
        "tables": [
          {
            "type": "TABLE",
            "name": "COMPUTER_T",
            "topic": "computers",
            "format": "JSON",
            "isWindowed": false
          },
          {
            "type": "TABLE",
            "name": "COMP_WATCH_BY_EMP_ID_T",
            "topic": "COMP_WATCH_BY_EMP_ID_T",
            "format": "AVRO",
            "isWindowed": false
          },
          {
            "type": "TABLE",
            "name": "EMPLOYEE_T",
            "topic": "employees",
            "format": "JSON",
            "isWindowed": false
          }
        ]
      }
    ]
  • Get runtime stats for a table/stream using DESCRIBE EXTENDED and jq:

    $ curl -s -X "POST" "http://localhost:8088/ksql" \
           -H "Content-Type: application/vnd.ksql.v1+json; charset=utf-8" \
           -d '{
        "ksql": "DESCRIBE EXTENDED COMPUTER_T;"
      }'| jq '.[].sourceDescription.statistics'
    "consumer-messages-per-sec:         0 consumer-total-bytes:       193 consumer-total-messages:         3     last-message: 2019-01-17T11:54:08.593Z"
Note
To use single quotes in a curl argument (e.g. -d) you need to escape them correctly. For KAFKA_TOPIC='pageviews' you need to use KAFKA_TOPIC='\''pageviews'\''

Robin Moffatt

Robin Moffatt works on the DevRel team at Confluent. He likes writing about himself in the third person, eating good breakfasts, and drinking good beer.

Story logo

© 2025