Restful requests using curl with Astra Streaming
Pulsar offers a RESTful API for administrative tasks. When you create a tenant in Astra Streaming, all supporting APIs are enabled.
To interact with your Astra Streaming tenant you will need two pieces of information: a token and the service URL. This guide will show you how to gather that information and test your connection.
The Pulsar documentation} has a full reference for each API supported in a cluster. This reference will be helpful as you look to automate certain actions in your Astra Streaming tenant. |
Finding your tenant’s web service URL
First, you need to know where to send your curl request. This is known as the "Web Service URL".
Pulsar has other connection URLs, and it’s easy to confuse them. The Web Service URL starts with "http(s)", while the Broker Service URL starts with "pulsar(+ssl)". |
After you have signed in to your Astra account, navigate to the "Connect" tab in any of your streaming tenants.
|
Choose the "Details" area of the page and find the section labeled "Tenant Details". This is a listing of all essential info you will need to communicate with your Pulsar tenant.
|
Locate the value for the "Web Service URL" and copy the address to a safe place.
Retrieving your Pulsar token in Astra Streaming
Next, you need an authentication token. Most APIs use tokens to authenticate a request, and Pulsar follows this same pattern.
Don’t confuse your Pulsar token with your Astra token - the concept is the same, but it’s a different authentication. More details are here. |
To create a new Pulsar token in your Astra Streaming tenant, navigate to the "Settings" tab in the Astra portal.
|
Click "Create Token" and choose the time to expire. Be smart about this choice - "Never Expire" isn’t always the best option. A window will appear with the newly generated token - it’s a long string of letters and numbers.
|
Click the clipboard icon to copy the token to your clipboard, and paste the token in a safe place. This is the only time you will be able to copy it.
Example curl call
You now have the two necessary ingredients to make RESTful calls to your Astra Streaming tenant. Let’s put them to use!
Set the required variables in a terminal window.
PULSAR_TOKEN="<REPLACE-ME-WITH-TOKEN>"
WEB_SERVICE_URL="<REPLACE-ME-WITH-URL>"
Run the following curl command to list all the built-in sink connectors.
curl -sS --fail --location --request GET \
-H "Authorization: $PULSAR_TOKEN" \
"$WEB_SERVICE_URL/admin/v3/sinks/builtinsinks"
The output should be a very long JSON-formatted string containing details about all the sink connectors waiting for you to have fun with 😀.
If your curl command doesn’t go so smoothly, add -v to your call.The -v is for verbose, and prints more detail about what problem has occurred.
|
What’s next?
Now it’s time to put your tenant’s API to use! Here are a few suggestions.