Updating a partial entry of an existing object in your database can be easily accomplished by hitting a REST endpoint that includes your table name, and a body of information that fits your table schema – but you are allowed to submit only a partial amount of data for that row instead of every key/value pair that exists. Sending a network request to the route will then construct a SQL query that sanitizes and updates the data into the designated table, at the row with a matching primary key as sent in via the URL.
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
Updating some fields in an existing database object happens via an HTTP PATCH request with a route of /rest/{YOUR_TABLE_NAME}/{PK_VALUE}
and a body object that matches the schema of your database table.
-
YOUR_TABLE_NAME
can be replaced with any table name in your database -
PK_VALUE
should match the unique primary key column identifier for this row. If your primary key column wasid
and the entry you wanted to update had a value of 5 in that field, you would pass5
in the URL.
Example
Use the below example to get started.
curl --location --request PATCH 'https://starbasedb.YOUR-IDENTIFIER.workers.dev/rest/users/5' \
--header 'Authorization: Bearer ABC123' \
--header 'Content-type: application/json' \
--data-raw '{
"email": "brayden+1@outerbase.com"
}'