Skip to content

Latest commit

 

History

History
97 lines (77 loc) · 3.9 KB

README.md

File metadata and controls

97 lines (77 loc) · 3.9 KB

Chasing Horizons API

The Chasing Horizons API is a backend service for managing blog posts, users, tags, comments, and photos. This API supports CRUD operations for posts, users, and tags, user authentication, and handling media uploads. It uses JWT tokens for secure authentication and integrates with Firebase for file storage.

Features

User Management: User registration, login, update, and deletion.
Post Management: Create, update, view, and delete blog posts.
Comment Management: Add and manage comments on blog posts.
Tag Management: Create, update, and delete tags to categorize posts.
Photo Management: Upload, view, and manage photos.
Authentication: JWT-based authentication for secure access to API endpoints.

Technology Stack

Node.js: Backend runtime environment.
Express: Web framework for building API routes.
MongoDB: NoSQL database for persisting data.
Firebase: Used for storing photos.
JWT (jsonwebtoken): For authentication and secure access.
Mongoose: MongoDB object modeling for Node.js.

API Endpoints

Auth Endpoints
POST /v1/auth/login - Login an existing user and generate a JWT token.

User Endpoints
POST /v1/user/ - Register a new user.
PATCH /v1/user/ - Update user information.
GET /v1/user/ - Retrieve the currently logged-in user.
DELETE /v1/user/ - Delete the logged-in user account.

Post Endpoints
POST /v1/post/ - Create a new post.
GET /v1/post/ - Retrieve all posts.
GET /v1/post/{postId} - Get details of a specific post.
PATCH /v1/post/{postId} - Update an existing post.
DELETE /v1/post/{postId} - Delete a post.

Comment Endpoints
POST /v1/comment/{postId} - Add a comment to a specific post.
GET /v1/comment/{postId} - Retrieve all comments on a specific post.

Tag Endpoints
POST /v1/tag/ - Create a new tag.
GET /v1/tag/ - Retrieve all tags.
PUT /v1/tag/{tagId} - Update an existing tag.
DELETE /v1/tag/{tagId} - Delete a tag.

Photo Endpoints
POST /v1/photo/ - Upload a new photo.
GET /v1/photo/ - Retrieve all uploaded photos.
GET /v1/photo/{photoId} - Retrieve a specific photo by its ID.

Health Check
GET /health - Check the health status of the API.

Environment Variables

Create a .env file in the root directory and configure the following variables:
DB_URI=mongodb://localhost:27017/chasing-horizons
PORT=8000
JWT_SECRET=your_jwt_secret_here
FIREBASE_PROJECT_ID=your_firebase_project_id
FIREBASE_PRIVATE_KEY=your_firebase_private_key
FIREBASE_CLIENT_EMAIL=your_firebase_client_email

Setup and Installation

Clone the repository:
git clone https://github.com/yourusername/chasing-horizons.git

Install dependencies:
npm install

Set up environment variables in the .env file (as mentioned above).

Run the server:
npm start

The API will be available at http://localhost:8000

Dependencies

express: Web framework for Node.js.
jsonwebtoken: For generating and verifying JWT tokens.
mongoose: MongoDB object modeling.
firebase-admin: For integrating Firebase storage.
bcrypt: For securely hashing passwords.
dotenv: For managing environment variables.
multer: For handling file uploads.
express-async-handler: Simplifies async error handling in Express.

API Testing with Insomnia

To test the API, you can import the provided Insomnia workspace and test the endpoints directly.
Download the insomnia/api-requests.json file from this repository.
Open Insomnia and go to Application Menu > Import/Export > Import Data.
Select the downloaded api-requests.json file to load the API requests for this project.

License

This project is licensed under the MIT License.