This repository contains the backend solution for the Stuneckt Backend Assignment.
The assignment is to develop a RESTful API for a social media platform. The API allows users to create posts, view all posts, view posts by a specific user, and paginate through the posts. Additionally, users can view their own posts.
- Node.js
- Express.js
- MongoDB
- Mongoose
- TypeScript
-
Clone the repository:
git clone https://github.com/ikunal-04/stuneckt.git
-
Install dependencies:
cd stuneckt npm install
-
Set up environment variables:
- Create a
.env
file in the root directory - Add the following environment variables:
PORT=3000 MONGODB_URI=<your_mongodb_uri> JWT_SECRET=<your_jwt_secret>
- Create a
-
Start the server:
npm start
-
Create a post
- URL:
/api/posts/create
- Method:
POST
- Request Body:
{ "description": "Your post description" }
- Authorization: Required
- URL:
-
Get all posts
- URL:
/api/posts/allposts
- Method:
GET
- Query Parameters:
page
(optional): Page number for pagination (default is 1)limit
(optional): Number of posts per page (default is 10)
- URL:
-
Get posts by a specific user
- URL:
/api/posts/userposts
- Method:
GET
- Authorization: Required
- Query Parameters:
page
(optional): Page number for pagination (default is 1)limit
(optional): Number of posts per page (default is 10)
- URL:
-
Get User Details
- URL:
/api/user/profile
- Method:
GET
- Authorization: Required
- URL:
-
Create a post
- URL:
/api/user/update
- Method:
PUT
- Request Body:
{ "name": "Your name", "email": "Your email" }
- Authorization: Required
- URL:
This application is deployed on vercel i.e. both the frontend and the backend api's.