Skip to main content
GET
/
health
Health Check
curl --request GET \
  --url https://api.example.com/health
{
  "message": "<string>"
}
Check the health status of the API and verify database connectivity. This endpoint is useful for monitoring, uptime checks, and ensuring the service is operational.

Description

The health check endpoint performs a database ping operation to verify that:
  • The API server is running
  • The MongoDB database connection is active
  • Database operations can be performed

Authentication

No authentication required - this is a public endpoint.

Response

message
string
Status message indicating database health

Status Codes

  • 200 OK - API and database are healthy
  • 404 Not Found - Database connection failed (includes error details)
The 404 status code is used instead of 503 for database failures. This is an implementation detail of the current API version.

Request Example

curl -X GET https://api.example.com/health

Response Examples

{
  "message": "Database is active"
}

Implementation Details

The health check uses MongoDB’s ping command:
await app.db.command("ping")
This command:
  • Tests the connection to the database
  • Verifies authentication (if required)
  • Returns quickly (typically less than 10ms)
  • Minimal resource usage

Monitoring Best Practices

Database Connection

The health check validates the connection to:
  • Database: ShortURL
  • Collections: URLMap, URLStats
  • Connection: Established during app startup via MongoDB Motor (async driver)
A failed health check indicates database connectivity issues. Common causes include:
  • MongoDB server is down
  • Network connectivity problems
  • Authentication failures
  • Connection pool exhaustion
Check the error message in the response detail field for specific failure information.
  • GET / - Welcome message (minimal check, no database validation)
  • GET /validate_token - Check if an access token is valid

Build docs developers (and LLMs) love