Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pvnm4/Social-Media-Backend/llms.txt

Use this file to discover all available pages before exploring further.

The Social Media Backend exposes a RESTful HTTP API built with FastAPI and backed by PostgreSQL. Every endpoint returns JSON, and every request body must be JSON (with Content-Type: application/json) — with one exception: POST /login accepts form-encoded credentials following the OAuth2 password flow. Most endpoints require a JWT Bearer token obtained from POST /login; a small number of read/registration endpoints are publicly accessible without authentication.

Base URL

For local development the API is available at:
http://localhost:8000
The root path (GET /) returns a welcome message that confirms the server is running:
{"message": "Welcome to the Social Media App"}
When the application is deployed to Render (or any other hosting provider), replace http://localhost:8000 with the provider-assigned base URL. All relative paths documented here remain unchanged.

Authentication

The API uses signed JWT Bearer tokens for authentication. Tokens are created with the HS256 algorithm and contain the authenticated user’s user_id in the payload. Expiry is controlled by the ACCESS_TOKEN_EXPIRE_MINUTES environment variable (configured in app/config.py via Pydantic Settings). Obtaining a token Call POST /login with the user’s email and password as form-encoded data. On success the response contains an access_token string and a token_type of "bearer". Using a token Include the token in the Authorization header of every protected request:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
If the header is absent, malformed, or the token is expired/invalid, FastAPI returns 401 Unauthorized with the detail "Could not validate credentials".

Request format

EndpointContent-TypeBody format
POST /loginapplication/x-www-form-urlencodedusername=<email>&password=<password>
All other mutating endpointsapplication/jsonJSON object matching the endpoint’s schema
The username field in the login form must contain the user’s email address. This is a FastAPI OAuth2PasswordRequestForm convention — the field is named username in the wire format but is validated against the email column in the database.

Response format

All responses are JSON. The following HTTP status codes are used for successful operations:
ScenarioStatus code
Successful read (GET)200 OK
Successful authentication (POST /login)200 OK
Successful resource creation (POST /users/, POST /posts/, POST /vote/)201 Created
Successful deletion (DELETE /posts/{id})204 No Content — response body is empty
List endpoints (e.g. GET /posts/) return a JSON array. Post list items follow the PostOut schema, which wraps each Post object together with its integer vote count.

Common error codes

StatusMeaning
400Bad request / validation error
401Missing or invalid JWT token
403Forbidden — invalid credentials or not the resource owner
404Resource not found
409Conflict — resource already exists (duplicate email on registration, or duplicate vote)
422Unprocessable entity — request body failed Pydantic validation

Available endpoints

The table below summarises every route registered in the application. Routes marked Yes under Auth require a valid Authorization: Bearer <token> header.
MethodPathAuthDescription
POST/loginNoAuthenticate and get a JWT access token
POST/users/NoRegister a new user
GET/users/NoGet a user by ID
GET/posts/YesList all posts with vote counts
GET/posts/YesGet a single post with its vote count
POST/posts/YesCreate a new post
PUT/posts/YesUpdate a post (owner only)
DELETE/posts/YesDelete a post (owner only)
POST/vote/YesCast or retract a vote on a post

Interactive docs

FastAPI automatically generates interactive API documentation from the OpenAPI schema. Two UIs are available while the server is running: Both UIs reflect all routes, request schemas, and response models defined in the application’s Pydantic models and FastAPI router declarations.

Build docs developers (and LLMs) love