Skip to content

Commit de07a63

Browse files
updated docs and changelog
1 parent ec13266 commit de07a63

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Enhance `/_mgmt/ping` endpoint to check if pgstac database is ready before responding ([#230](https://github.com/stac-utils/stac-fastapi-pgstac/pull/230))
8+
59
## [5.0.2] - 2025-04-07
610

711
### Fixed
Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
1-
::: stac_fastapi.pgstac.app
1+
# stac_fastapi.pgstac.app
2+
3+
## Overview
4+
5+
The `stac_fastapi.pgstac.app` module contains the main application configuration for the FastAPI-based STAC API that uses PgSTAC as the backend. This module defines how the application is constructed, which extensions are enabled, and how the API endpoints are registered.
6+
7+
## Key Components
8+
9+
### PgStacApi Class
10+
11+
```python
12+
class PgStacApi(StacApi)
13+
```
14+
15+
Extended version of the `StacApi` class that provides PgSTAC-specific functionality.
16+
17+
#### Methods
18+
19+
##### add_health_check
20+
21+
```python
22+
def add_health_check(self)
23+
```
24+
25+
Adds a health check endpoint at `/_mgmt/ping` that verifies database connectivity.
26+
27+
- The endpoint attempts to establish a database connection using the application's read connection pool.
28+
- It verifies PgSTAC is properly set up by querying the `pgstac.migrations` table.
29+
- Returns:
30+
- Status 200 with `{"message": "PONG", "database": "OK"}` when the database is healthy.
31+
- Status 503 with error details when the database cannot be reached or when PgSTAC is not properly set up.
32+
33+
### Application Creation
34+
35+
The module defines several key components for the FastAPI application:
36+
37+
1. **Settings**: Configuration settings for the application.
38+
2. **Extensions**: Various STAC API extensions that are enabled.
39+
3. **Search Models**: Request/response models for search endpoints.
40+
4. **Database Connection**: Configuration for connecting to PostgreSQL with PgSTAC.
41+
42+
### Lifespan
43+
44+
```python
45+
@asynccontextmanager
46+
async def lifespan(app: FastAPI)
47+
```
48+
49+
Manages the application lifespan:
50+
- Connects to the database during startup
51+
- Closes database connections during shutdown
52+
53+
## Usage
54+
55+
The module creates a FastAPI application with a PgSTAC backend:
56+
57+
```python
58+
api = PgStacApi(
59+
app=FastAPI(...),
60+
settings=settings,
61+
extensions=application_extensions,
62+
client=CoreCrudClient(pgstac_search_model=post_request_model),
63+
...
64+
)
65+
app = api.app
66+
```
67+
68+
The application can be run directly with uvicorn or used as a Lambda handler.

0 commit comments

Comments
 (0)