An action maps an HTTP endpoint in your Express app to a CRUD operation on a Firestore collection. You register all actions by calling addActions([...]) on your FirebaseExpressSdk instance.
Registering actions
Pass an array of action objects to addActions(). Each object requires three fields: collection, endpoint, and request.
firebaseExpressSdk.addActions([
// Simple GET — fetch all documents
{
collection: "users",
endpoint: "/api/users",
request: { type: "GET" },
},
// GET by param — fetch a single document by ID
{
collection: "users",
endpoint: "/api/users/:id",
request: { type: "GET", paramKey: "id" },
},
// POST — create a new document
{
collection: "users",
endpoint: "/api/users",
request: { type: "POST" },
},
// DELETE by param — delete a document by ID
{
collection: "users",
endpoint: "/api/users/:id",
request: { type: "DELETE", paramKey: "id" },
},
]);
addActions() also starts the Express server listening. Call it after all other app setup — middleware, configuration, and any non-SDK routes — is complete.
Action fields
collection
The name of the Firestore collection this action operates on. Must match a key in the collections config you passed to the constructor.
endpoint
The Express route path for this action, e.g. "/api/users" or "/api/users/:id".
request
An object that controls how the SDK handles incoming HTTP requests.
| Field | Required | Description |
|---|
type | Yes | The HTTP method: GET, POST, PUT, PATCH, or DELETE. |
paramKey | No | The URL parameter name used to identify a document, e.g. "id" for a route like /api/users/:id. |
query | No | A filter, sort, and limit configuration object for GET actions. |
GET variants
The combination of paramKey and query on a GET action determines its behavior:
paramKey | query | Behavior |
|---|
| absent | absent | Fetches all documents in the collection. |
| present | absent | Fetches the single document whose ID matches the URL parameter. |
| absent | present | Fetches documents filtered and/or sorted by the query config. |
| present | present | Fetches documents filtered by a where clause using the URL parameter value. |
See the Guides section for detailed, working examples of each request type, including filtering and sorting with query.