Creating new data objects and inserting them into your SQL tables can be easily accomplished by hitting a REST endpoint that includes your table, and a body of information that fits your table schema. Sending a network request to the route will then construct a SQL query that sanitizes and inserts the data into the designated table.
Request Structure
Every request is simple and standardized in how you interact with a table resource in your database. Follow the below rules and see the example at the bottom for how to apply it to your use case.
Authorization Headers
Every request sent to a StarbaseDB instance must pass in an Authorization Bearer token with a token value matching the value defined in your wrangler.toml
file where the variable name is AUTHORIZATION_TOKEN
. For any request that does not have a matching token value, the request will automatically be denied and cannot pass into the storage layer of your database.
An example cURL including the Bearer token can be seen below.
curl --location 'https://starbasedb.YOUR-IDENTIFIER.workers.dev/rest/your_table_name' \
--header 'Authorization: Bearer ABC123' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Content-type=application/json'
Route
Inserting objects into your database table happens via an HTTP POST request with a route of /rest/{YOUR_TABLE_NAME}
and a body object that matches the schema of your database.
YOUR_TABLE_NAME
can be replaced with any table name in your database
Example
Use the below example to get started.
curl --location 'https://starbasedb.YOUR-IDENTIFIER.workers.dev/rest/users' \
--header 'Authorization: Bearer ABC123' \
--header 'Content-type: application/json' \
--data-raw '{
"name": "Brayden",
"email": "brayden@outerbase.com"
}'