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
> 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
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"}'
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
query {
findProduct(productId: 123)
}
{"data":{"findProduct":"T-Shirt"}}
> 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"