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.

 

  1. Create a database with demo data

  2. Create an authentication secret

  3. Set the FAUNA_SECRET environment variable

    Set the FAUNA_SECRET environment variable to your key’s secret.

    export FAUNA_SECRET=<KEY_SECRET>
  4. 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
          }
        ]
      },
      ...
    }
\