Introduction
The Adoptme API is a RESTful service for managing pet adoptions, built with Express.js and MongoDB. This API allows you to manage users, pets, adoptions, and authentication sessions.Base URLs
The default development port is 8080, but can be configured via the
PORT environment variable.Authentication
The API uses cookie-based JWT authentication for protected endpoints.How it works:
- Register or Login via
/api/sessions/registeror/api/sessions/login - Receive a JWT token stored in a cookie named
coderCookie - The cookie is automatically sent with subsequent requests
- Token expires after 1 hour
Authentication Flow
Request Format
All requests must use JSON format with the appropriateContent-Type header.
Response Format
All API responses follow a consistent JSON structure:Success Response
Error Response
HTTP Status Codes
The API uses standard HTTP status codes:| Code | Description | Common Usage |
|---|---|---|
200 | OK | Successful GET, PUT, DELETE requests |
201 | Created | Successful POST requests (resource created) |
400 | Bad Request | Missing required fields, validation errors |
404 | Not Found | Resource doesn’t exist |
500 | Internal Server Error | Server-side errors |
Error Handling
All controllers implement try-catch blocks with consistent error responses:Common Error Patterns
Rate Limiting
Currently, there is no rate limiting implemented in the API. This should be added for production use.
API Resources
The API provides the following resource endpoints:Users
Manage user accounts, profiles, and pet ownership.- Base Path:
/api/users - View Users Documentation
Pets
Manage pets available for adoption, including image uploads.- Base Path:
/api/pets - View Pets Documentation
Adoptions
Create and manage adoption records linking users to pets.- Base Path:
/api/adoptions - View Adoptions Documentation
Sessions
Authentication endpoints for registration, login, and session management.- Base Path:
/api/sessions - View Sessions Documentation
Mocks
Generate mock data for testing purposes.- Base Path:
/api/mocks - View Mocks Documentation
Interactive API Documentation
The API includes Swagger UI documentation at:src/docs/documentacion.yaml.
Swagger Configuration
Database
The API uses MongoDB with Mongoose ODM:- Default Connection:
mongodb://127.0.0.1:27017 - Database Name:
adoptme - Configurable via:
MONGO_URLandDB_NAMEenvironment variables
Collections
- Users - User accounts and authentication
- Pets - Pet records and adoption status
- Adoptions - Adoption records linking users to pets
Quick Start Example
Next Steps
Users API
Manage user accounts and profiles
Pets API
Manage pets and image uploads
Adoptions API
Create and track adoptions
Sessions API
Authentication and session management