Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now GA. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. Migrating from v3 of the CLI? See the CLI migration guide. |
HTTP API quick start
Use the Fauna Core HTTP API to query e-commerce demo data using curl or any client that can make HTTP requests.
-
Create a database with demo data
Log in to the Fauna Dashboard, and create a database with the following configuration:
-
Region Group: Choose your preferred region group, which determines where your data resides.
-
Use demo data: Enabled.
-
Enable backups: Disabled.
Leave the other options as is.
-
-
Create an authentication secret
Fauna supports several types of authentication secrets. For this quick start, create a key, which is a type of secret, with the built-in
server-readonly
role:-
In the Dashboard’s Explorer page, select your demo database.
-
In the database’s Keys tab, click Create Key.
-
Choose a Role of server (read-only).
-
Click Save.
-
Copy the Key Secret.
-
-
Set the FAUNA_SECRET environment variable
Set the
FAUNA_SECRET
environment variable to your key’s secret.export FAUNA_SECRET=<KEY_SECRET>
-
Make an HTTP request
To run a query, use curl to make a request to the Core HTTP API’s Query endpoint.
Fauna routes and authorizes the request using the secret in
FAUNA_SECRET
environment variable. The secret is scoped to a specific database. The query only runs in this database.curl -X POST \ "https://db.fauna.com/query/1" \ -H "Authorization: Bearer $FAUNA_SECRET" \ -H "Content-Type: application/json" \ -H "X-Format: simple" \ -d '{ "query": "Product.sortedByPriceLowToHigh() { name, description, price }" }'
The response’s
data
property contains the results of the query:{ "data": { "data": [ { "name": "single lime", "description": "Conventional, 1 ct", "price": 35 }, { "name": "cilantro", "description": "Organic, 1 bunch", "price": 149 }, { "name": "limes", "description": "Conventional, 16 oz bag", "price": 299 }, { "name": "organic limes", "description": "Organic, 16 oz bag", "price": 349 }, { "name": "avocados", "description": "Conventional Hass, 4ct bag", "price": 399 }, { "name": "pizza", "description": "Frozen Cheese", "price": 499 }, { "name": "cups", "description": "Translucent 9 Oz, 100 ct", "price": 698 }, { "name": "taco pinata", "description": "Giant Taco Pinata", "price": 2399 }, { "name": "donkey pinata", "description": "Original Classic Donkey Pinata", "price": 2499 } ] }, ... }
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!