Exploring Stargate APIs from the command line - REST
In this section you will use our httpie configuration to take a look at the Stargate REST API.
- REST - List Keyspaces
- REST - Create a Table
- REST - Retrieve Tables
Did your token expire? Reset it with this command.
/workspace/httpie-katapod/token.sh
The first thing that needs to happen is to create a table. HTTPie will handle the authentication and create the right server based on your .astrarc file, but you'll need to make sure and use that "library" keyspace.
Here are the steps:
http http://localhost:8082/v2/schemas/keyspaces
Do you see 'library' in there? Great, we're ready to move on.
You could also check for a specific keyspace:
http http://localhost:8082/v2/schemas/keyspaces/library
echo -n '{
"name": "users",
"columnDefinitions":
[
{
"name": "firstname",
"typeDefinition": "text"
},
{
"name": "lastname",
"typeDefinition": "text"
},
{
"name": "favorite color",
"typeDefinition": "text"
}
],
"primaryKey":
{
"partitionKey": ["firstname"],
"clusteringKey": ["lastname"]
},
"tableOptions":
{
"defaultTimeToLive": 0,
"clusteringExpression":
[{ "column": "lastname", "order": "ASC" }]
}
}' | http POST localhost:8082/v2/schemas/keyspaces/library/tables
Just to be sure, go ahead and ask for a listing of the tables in the library keyspace:
http localhost:8082/v2/schemas/keyspaces/library/tables
or specify the table you want:
http localhost:8082/v2/schemas/keyspaces/library/tables/users