rmoff's random ramblings
about talks

Using httpie with the Kafka REST Proxy

Published Mar 8, 2019 by in Httpie, Kafka REST Proxy at https://rmoff.net/2019/03/08/using-httpie-with-the-kafka-rest-proxy/

This shows how to use httpie with the Confluent REST Proxy.

Send data ðŸ”—

echo '{"records":[{"value":{"foo":"bar"}}]}' | \
  http POST http://localhost:8082/topics/jsontest \
  Content-Type:application/vnd.kafka.json.v2+json Accept:application/vnd.kafka.v2+json

Response:

HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 100
Content-Type: application/vnd.kafka.v2+json
Date: Fri, 08 Mar 2019 15:24:53 GMT
Server: Jetty(9.4.12.v20180830)
Vary: Accept-Encoding, User-Agent

{
    "key_schema_id": null,
    "offsets": [
        {
            "error": null,
            "error_code": null,
            "offset": 3,
            "partition": 0
        }
    ],
    "value_schema_id": null
}

Consume data ðŸ”—

Create a consumer ðŸ”—

echo '{"name": "rmoff_consumer_instance", "format": "json", "auto.offset.reset": "earliest"}' | \
  http POST http://localhost:8082/consumers/rmoff_consumer_group \
  Content-Type:application/vnd.kafka.v2+json

Response:

HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 109
Content-Type: application/vnd.kafka.v2+json
Date: Fri, 08 Mar 2019 15:28:13 GMT
Server: Jetty(9.4.12.v20180830)
Vary: Accept-Encoding, User-Agent

{
    "base_uri": "http://rest-proxy:8082/consumers/rmoff_consumer_group/instances/rmoff_consumer_instance",
    "instance_id": "rmoff_consumer_instance"
}

Create a subscription for the consumer ðŸ”—

echo '{"topics":["jsontest"]}' | \
http POST http://localhost:8082/consumers/rmoff_consumer_group/instances/rmoff_consumer_instance/subscription \
Content-Type:application/vnd.kafka.v2+json

Response

HTTP/1.1 204 No Content
Date: Fri, 08 Mar 2019 15:30:33 GMT
Server: Jetty(9.4.12.v20180830)

Read all available messages ðŸ”—

http http://localhost:8082/consumers/rmoff_consumer_group/instances/rmoff_consumer_instance/records \
Accept:application/vnd.kafka.json.v2+json

Response:

HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Length: 113
Content-Type: application/vnd.kafka.json.v2+json
Date: Fri, 08 Mar 2019 15:31:42 GMT
Server: Jetty(9.4.12.v20180830)
Vary: Accept-Encoding, User-Agent

[
    {
        "key": null,
        "offset": 0,
        "partition": 0,
        "topic": "jsontest",
        "value": {
            "foo": "bar"
        }
    }
]    

Change the offset for the consumer ðŸ”—

This is useful if you want to reconsume messages, or maybe seek past a bad message.

echo '{ "offsets": [ { "topic": "jsontest", "partition": 0, "offset": 1 } ] }' | \
http POST localhost:8082/consumers/rmoff_consumer_group/instances/rmoff_consumer_instance/positions \
Content-Type:application/vnd.kafka.v2+json

Response:

HTTP/1.1 204 No Content
Date: Fri, 08 Mar 2019 15:54:48 GMT
Server: Jetty(9.4.12.v20180830)

Delete the consumer ðŸ”—

http DELETE http://localhost:8082/consumers/rmoff_consumer_group/instances/rmoff_consumer_instance \
Content-Type:application/vnd.kafka.v2+json

Response:

HTTP/1.1 204 No Content
Date: Fri, 08 Mar 2019 15:33:06 GMT
Server: Jetty(9.4.12.v20180830)

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