This is a project from Roadmap.sh. It's a RESTful API that supports full CRUD (Create, Read, Update, Delete) operations for managing blog posts. With this API, you can create new posts, retrieve existing ones, update content, and delete posts as needed.
The project includes multiple data storage models for managing posts, including Local (in-memory), MongoDB, and MySQL.## Project Structure
BLOGGING_API/
├── controlls/ # Contains controller logic
├── models/ # Data models for different storage methods
├── routes/ # API route definitions
├── schemas/ # Validation schemas (with ZOD)
├── .env # Environment variables
├── api.http # HTTP client requests for testing endpoints
├── app.js # Main app entry point
├── server-with-local.js # Server setup using local storage
├── server-with-mongo.js # Server setup using MongoDB
The project includes a controller responsible for handling all user input. It performs data validation when necessary and delegates operations to the selected model. There are separate models for each storage method: one for the local file system, another for MongoDB and a soon to add MySql.
You can test the endpoints of the api with the file called api.http. You need to have installed the following extension:
Clone the project
git clone https://github.com/Jayslen/blogging-platform-APIInstall dependencies
npm install npm run start:localTo run the project with MongoDB, follow these steps:
-
Add the following environment variables to your .env file to configure the project correctly.
MONGO_URI -
Then run
npm run start:mongo
To run the project with MySQL, follow these steps:
-
Create the database using the SQL script located in the models/mysql directory.
-
Add the following environment variables to your .env file to configure the project correctly.
MYSQL_HOSTMYSQL_PORTMYSQL_USERMYSQL_DATABASE -
Then run
npm run start:mysql
GET /posts| Parameter | Type | Description |
|---|---|---|
None |
None |
No parameter is required |
GET /post/${id}| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of item to fetch |
GET /post?term=${term}| Parameter | Type | Description |
|---|---|---|
term |
string |
Required. filter posts by a search term on the title, content or category fields |
Delete /posts/${id}| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of post to delete it |
GET /posts/${id}| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Id of item to fetch |
POST /posts| Body Request | Description |
|---|---|
{title: "string", content: "string", category: "string", tags: ["array"]} |
Required. to create post |
UPDATE /posts/${id}| Parameter | Type | Description | Body Request |
|---|---|---|---|
id |
string |
Required. Id of post to update | object |