API Endpoints
Relevant source files
The following files were used as context for generating this wiki page:
This document provides a technical overview of the API endpoints available in the landing-emrgent project. The backend is built using Python with the FastAPI framework, providing a simple RESTful service. It is designed to interact with a MongoDB database for data persistence and is intended to be consumed by the React frontend application. The API's primary function is to handle status checks.
Backend Architecture
The backend server is a FastAPI application that uses an APIRouter to prefix all routes with /api. It connects to a MongoDB database using connection details specified in environment variables. CORS (Cross-Origin Resource Sharing) is enabled to allow requests from any origin, which is typical for development environments connecting a separate frontend and backend.
Sources: backend/server.py:1-68
Core Components
| Component | Technology | Purpose | Source File |
|---|---|---|---|
| Web Framework | FastAPI | Creates the web server and API endpoints. | backend/server.py |
| API Routing | APIRouter | Organizes all endpoints under a common /api prefix. | backend/server.py:22 |
| Database Connector | motor_asyncio | Provides an asynchronous client for interacting with the MongoDB database. | backend/server.py:14 |
| Data Validation | Pydantic | Defines data models (BaseModel) for request and response validation. | backend/server.py:28-36 |
| Middleware | CORSMiddleware | Allows cross-origin requests, enabling the frontend to communicate with the API. | backend/server.py:57-63 |
| Environment Mgmt | python-dotenv | Loads environment variables from a .env file. | backend/server.py:9 |
System Architecture Diagram
The following diagram illustrates the high-level architecture of the backend system.
Sources: backend/server.py
Environment Configuration
The server's database connection is configured via environment variables loaded from a .env file.
| Variable | Description |
|---|---|
MONGO_URL | The connection string for MongoDB. |
DB_NAME | The name of the database to use. |
Sources: backend/server.py:13-15
API Endpoint Definitions
All endpoints are defined within the api_router and are accessible under the /api path prefix.
Sources: backend/server.py:22, backend/server.py:55
| Method | Path | Description |
|---|---|---|
GET | / | A root endpoint for basic connectivity checks. |
POST | /status | Creates a new status check record in the database. |
GET | /status | Retrieves a list of all status check records. |
GET /api/
A simple health-check endpoint that returns a "Hello World" message.
- Request:
GET /api/ - Response:
200 OK{ "message": "Hello World" }
Sources: backend/server.py:40-42
POST /api/status
This endpoint receives a client name, creates a new status check document with a unique ID and a timestamp, saves it to the status_checks collection in MongoDB, and returns the created object.
Request Flow
Sources: backend/server.py:44-49
Request Body
The request body must be a JSON object matching the StatusCheckCreate model.
| Field | Type | Description |
|---|---|---|
client_name | string | The name of the client. |
Sources: backend/server.py:35-36
Response Body
The response is a JSON object matching the StatusCheck model.
Sources: backend/server.py:44
GET /api/status
This endpoint queries the status_checks collection in MongoDB and returns a list of all documents, limited to the first 1000 records found.
Request Flow
Sources: backend/server.py:51-54
Response Body
The response is a JSON array of objects matching the StatusCheck model.
[
{
"id": "a1b2c3d4-e5f6-...",
"client_name": "WebApp",
"timestamp": "2023-10-27T10:00:00Z"
}
]
Sources: backend/server.py:51
Data Models and Database Schema
Pydantic models are used to define the structure and types for API request and response bodies, ensuring data validation.
Sources: backend/server.py:28-36
Pydantic Class Diagram
This diagram shows the Pydantic models used in the API.
StatusCheck Model
This model represents a status check record as stored in the database and returned by the API.
| Field | Type | Description | Default Value |
|---|---|---|---|
id | str | A unique identifier for the record. | uuid.uuid4() |
client_name | str | The name of the client that was checked. | N/A |
timestamp | datetime | The UTC timestamp when the check was created. | datetime.utcnow() |
Sources: backend/server.py:29-33
MongoDB Schema
The status_checks collection in MongoDB stores documents that correspond to the StatusCheck Pydantic model.
Sources: backend/server.py:48, backend/server.py:52
Frontend Interaction
The project includes a React frontend designed to interact with this API. The use of axios for making HTTP requests is specified in its dependencies.
Sources: frontend/package.json:28
Contact Form Submission (Mocked)
The LandingPage.jsx component includes a contact form. While the component itself does not contain a live API submission handler, the project provides a mock function that simulates this interaction.
The mockFormSubmission function in mock.js demonstrates the intended client-side logic for a form submission. It simulates an asynchronous API call with a 1-second delay and returns a success message. This indicates an intention to eventually connect the frontend form to a backend endpoint, though one for form submission is not defined in the current server.py.
// Mock form submission handler
export const mockFormSubmission = {
submitContactForm: async (formData) => {
// Simulate API call delay
await new Promise(resolve => setTimeout(resolve, 1000));
// Mock successful submission
console.log("Form submitted with data:", formData);
return {
success: true,
message: "Thank you! Your strategy session has been scheduled. You'll receive a confirmation email shortly.",
confirmationNumber: `SS-${Date.now()}`
};
}
};
Sources: frontend/src/mock.js:203-215, frontend/src/components/LandingPage.jsx:501-541
Third-Party Analytics
The frontend also communicates with an external service, PostHog, for analytics and session recording. This is configured in the main index.html file and represents another form of data being sent from the client.
Sources: frontend/public/index.html:84-188
Conclusion
The API for landing-emrgent is a straightforward service built with FastAPI. It currently provides endpoints for creating and retrieving status checks, persisting the data in a MongoDB collection. The architecture is clean, using an API router for organization and Pydantic models for robust data validation. While the backend is simple, the frontend's structure and mock data suggest plans for more complex interactions, such as handling contact form submissions.