Tutorial #1 - Build API Backends with Quick

This post is part of our introduction series. In this tutorial you will learn how to manage stream data applications and APIs with Quick. We show how simple it is to build scalable microservice platforms with Quick. We consider a demo use-case, an online-shop with products, users and purchases. With a few commands you manage data streams and API backends.

You can find the commands and the schemas used for this tutorial in our quick-examples repository

Install Quick CLI and create new context with your Quick URL and API Key.
> pip install \
quick-1.0.0-py3-none-any.whl -q
> quick -v
quick (version 1.0.0)
> quick context create \
--host $QUICK_HOST --key $KEY
Quick is based on Apache Kafka and organizes and stores event streams in topics. The first thing we need to do is create a topic for our product data. We name it product-topic and specify key as long and value as string. Quick supports efficient stream data ingestion via a RESTful web service. We send an ingest request via curl and specify in our Quick URL the topic name product-topic. We add the API Key and send the data we want to ingest in the format of topic key and value.
> quick topic create product-topic \
    --key long \
    --value string
Created new topic product-topic
> curl --request POST \
    --url https://$QUICK_URL/ingest/product-topic/ \
    --header 'content-type: application/json' \
    --header 'X-API-Key: $KEY' \
    --data '{"key": 123, "value": "T-Shirt"}'
Next we want to make this product topic queryable. Quick enables you to query data streams with APIs and GraphQL. All queries are processed by so called gateways. We create our first gateway product-gateway and design a GraphQL query findProduct that lets us search products in the product-topic based on the product key. Then we apply this schema to our gateway.
type Query {
  findProduct(productId: Long): 
     String @topic(name: "product-topic", keyArgument: "productId")
}
> quick gateway create product-gateway
Deployed gateway

> quick gateway apply product-gateway -f schema.gql
Applied definition for gateway product-gateway
We query the stream data with GraphQL and get the response in JSON format.
query {
   findProduct(productId: 123) 
}
{"data":{"findProduct":"T-Shirt"}}
We are also able to update and delete data in the topic.
> curl --request POST --url https://$QUICK_URL/ingest/product-topic/ \
    --header "content-type: application/json" \
    --header "X-API-Key:$KEY" \
    --data '[ {"key": 123, "value": "T-Shirt (black)"}, {"key": 456, "value": "Jeans"}, {"key": 789, "value": "Shoes"}]'
> curl --request DELETE --url https://$QUICK_URL/ingest/product-topic/123 \
    --header "X-API-Key:$KEY"