Fauna Core API
Download OpenAPI specification:Download
You can use the Fauna Core HTTP API to run FQL queries and consume event streams.
The Fauna client drivers and the Fauna Dashboard use the Core API to access data in Fauna databases.
Fauna Core API endpoints use https://db.fauna.com as the base URL.
For example, the full URL for the /query/1
(Query)
endpoint is https://db.fauna.com/query/1
.
Fauna routes requests to a database based on the secret used for authentication. All requests and queries run in the context of a single database.
You authenticate requests to Fauna Core API endpoints using an authentication secret. You pass the authentication secret in API requests as a bearer token.
Get an authentication secret
Fauna supports several secret types. For testing, you can create a key, which is a type of secret:
Log in to the Fauna Dashboard.
In the Dashboard, create a database and navigate to it.
In the upper left pane of the Dashboard's Explorer page, click the demo database, and click the Keys tab..
Click Create Key.
Choose a Role of server.
Click Save.
Copy the Key Secret. The secret is scoped to the database.
Query endpoint
Runs an FQL query. In Fauna, every query is a transaction that runs in the context of a single database.
Endpoint conventions
For other conventions for this endpoint, see Query API endpoint conventions.
Authorizations:
header Parameters
Authorization required | string Example: Bearer <FAUNA_SECRET> A Fauna authentication secret, passed as a bearer token. See Authentication for more details. |
X-Format | string Data format used to encode FQL values as JSON (and the reverse) in:
Accepts For more information, see Wire Protocol. |
X-Last-Txn-Ts | integer If set, acts as the minimum snapshot time the query executes.
Clients populate this based on the highest |
X-Linearized | boolean If true, unconditionally run the query as strictly serialized. This affects read-only transactions because transactions that write are already strictly serialized. See Strictly serialize read-only transactions. |
X-Max-Contention-Retries | integer The maximum number of times the system retries a transaction because of contention failure before an error is returned. |
X-Query-Tags | string A string-encoded set of caller-defined tags, which identify the request. Provided back in the logging and the query response body. The format is a list of key:value pairs. For example:
Each key and each value may only include the characters
All these are invalid:
Each key must be less than or equal to 40 bytes. Each value must be less than or equal to 80 bytes. There can be only a maximum of 25 key:value pairs, and the full header can't exceed 3000 bytes. |
X-Query-Timeout-Ms | integer Query timeout in milliseconds. |
X-Typecheck | boolean Enable or disable type checking of the query before evaluation.
Defaults to the value of |
Request Body schema: application/jsonrequired
required | object or string FQL query to run. Accepts an object or a string. |
arguments | object Object containing variables to interpolate into the The key of each object property is the name of the variable,
referenced in the Variable names must be valid FQL identifiers. Variable values should
be encoded using the data
format
specified in the |
Responses
Request samples
- Payload
- curl - Query object
- curl - Query string
{- "query": {
- "fql": [
- "Product.all().where(.stock ==",
- {
- "value": {
- "@int": "10"
}
}, - ")"
]
}
}
Response samples
- 200
- 400
- 401
- 409
- 429
- 440
- 500
- 502
- 503
- 504
{- "data": {
- "data": {
- "id": "410212968961146957",
- "coll": {
- "@mod": "Product"
}, - "ts": {
- "@time": "2099-07-29T14:26:37.650Z"
}, - "name": "cups",
- "description": "Translucent 9 Oz, 100 ct",
- "price": {
- "@int": 698
}, - "stock": {
- "@int": 100
}, - "category": {
- "@ref": {
- "id": "410212968956952653",
- "coll": {
- "@mod": "Category"
}
}
}
}
}, - "static_type": "Set<Product>",
- "summary": "",
- "txn_ts": 1727892962009660,
- "stats": {
- "compute_ops": 1,
- "read_ops": 18,
- "write_ops": 0,
- "query_time_ms": 215,
- "contention_retries": 0,
- "storage_bytes_read": 2158,
- "storage_bytes_write": 0,
- "rate_limits_hit": [ ]
}, - "schema_version": 1727880352326000
}
Stream endpoint
Subscribe to real-time events from a stream. See Event Streaming.
The Stream endpoint maintains an open connection and pushes events to the client as they occur. To asynchronously poll a stream for events, use the Event Feed endpoint.
Authorizations:
header Parameters
Authorization required | string Example: Bearer <FAUNA_SECRET> A Fauna authentication secret, passed as a bearer token. See Authentication for more details. |
X-Query-Timeout-Ms | integer Query timeout in milliseconds. |
Request Body schema: application/jsonrequired
token required | string Stream token for the event stream to subscribe to. |
cursor | string Cursor for a previous event. If provided, the stream replays any events that occurred after the cursor (exclusive). You can't pass both |
start_ts | integer Stream start time in microseconds since the Unix epoch.
This is typically a previous event's You can't pass both If you don't provide a |
Responses
Request samples
- Payload
- curl
{- "token": "<STREAM_TOKEN>",
- "cursor": "gsGabc123",
- "start_ts": 1710968002310000
}
Response samples
- 200
- 400
- 401
{- "type": "update",
- "data": {
- "@doc": {
- "id": "412095363338469409",
- "coll": {
- "@mod": "Product"
}, - "ts": {
- "@time": "2099-10-18T22:12:58.440Z"
}, - "name": "cups",
- "description": "Translucent 9 Oz, 100 ct",
- "price": {
- "@int": "698"
}, - "stock": {
- "@int": "100"
}, - "category": {
- "@ref": {
- "id": "412095363334275105",
- "coll": {
- "@mod": "Category"
}
}
}
}
}, - "txn_ts": 1729289578440000,
- "cursor": "gsGCGmcS3WoaGjneAAA=",
- "stats": {
- "read_ops": 1,
- "storage_bytes_read": 320,
- "compute_ops": 1,
- "processing_time_ms": 0,
- "rate_limits_hit": [ ]
}
}
Event Feed endpoint
The Event Feed endpoint is in beta. To use the Event Feed endpoint, you must have a Pro or Enterprise plan.
Asynchronously gets events from an event stream as a paginated Event Feed.
The Event Feed endpoint lets you periodically poll a stream for events. To synchronously subscribe to events, use the Stream endpoint.
Authorizations:
header Parameters
Authorization required | string Example: Bearer <FAUNA_SECRET> A Fauna authentication secret, passed as a bearer token. See Authentication for more details. |
X-Query-Timeout-Ms | integer Query timeout in milliseconds. |
Request Body schema: application/jsonrequired
token required | string Stream token for the event stream to subscribe to. |
cursor | string Cursor for a previous event. If provided, the stream replays any events that occurred after the cursor (exclusive). You can't pass both |
start_ts | integer Stream start time in microseconds since the Unix epoch.
This is typically a previous event's You can't pass both If you don't provide a |
page_size | integer Maximum number of events to return per page. Defaults to 16. Must be in the range 1 to 16000 (inclusive). |
Responses
Request samples
- Payload
- curl
{- "token": "<STREAM_TOKEN>",
- "cursor": "gsGabc123",
- "start_ts": 1710968002310000,
- "page_size": 10
}
Response samples
- 200
- 400
- 401
{- "events": [
- {
- "type": "update",
- "data": {
- "@doc": {
- "id": "412095363338469409",
- "coll": {
- "@mod": "Product"
}, - "ts": {
- "@time": "2099-10-18T21:54:07.340Z"
}, - "name": "cups",
- "description": "Translucent 9 Oz, 100 ct",
- "price": {
- "@int": "698"
}, - "stock": {
- "@int": "99"
}, - "category": {
- "@ref": {
- "id": "412095363334275105",
- "coll": {
- "@mod": "Category"
}
}
}
}
}, - "txn_ts": 1729288447340000,
- "cursor": "gsGCGmcS2P8aFEP9AAA=",
- "stats": {
- "read_ops": 1,
- "storage_bytes_read": 171,
- "compute_ops": 1,
- "processing_time_ms": 3,
- "rate_limits_hit": [ ]
}
}
], - "cursor": "gsGCGmcS2P8aFEP9AAA=",
- "has_next": false,
- "stats": {
- "read_ops": 9,
- "storage_bytes_read": 481,
- "compute_ops": 1,
- "processing_time_ms": 7,
- "rate_limits_hit": [ ]
}
}
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!