This is a simple RESTful API for a microblogging platform like Twitter or LinkedIn. It allows users to create posts, follow other users, and retrieve posts made by themselves or other users.
- Node.js installed on your machine.
- TypeScript installed globally on your machine
- MongoDB installed locally or a remote MongoDB instance.
-
Clone the repository:
git clone https://github.com/singhchanmeet/stuneckt-submission
-
Navigate to the server directory:
cd server
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.env
file in the root directory and define the following variables:PORT=3000 MONGODB_URI=mongodb://localhost:27017/microblogging JWT_SECRET=your_secret_key
Adjust the
MONGODB_URI
andJWT_SECRET
values as per your setup. -
Compile the Typescript to Javascript:
npm run build
-
Start the server:
npm run start
- POST /auth/signup
- Create a new user account.
- Request Body:
{ "username": "example_user", "email": "[email protected]", "password": "your_password", "name": "User Name" }
- POST /auth/login
- Log in an existing user.
- Request Body:
{ "username": "example_user", "password": "your_password" }
-
GET /user/profile
- Retrieve the profile of the authenticated user.
-
POST /user/follow/:usernameToFollow
- Follow a user by their username.
-
PUT /user/update
- Update the details of the authenticated user.
- Request Body:
{ "username": "new_username", "email": "[email protected]", "name": "New Name" }
- POST /posts/create
- Create a new post.
- Request Body:
{ "content": "This is a sample post content." }
- GET /posts/all
- Retrieve all posts.
- GET /posts/user/:userId
- Retrieve posts by a specific user.
- Replace
:userId
with the user's ID.
The API handles errors gracefully and returns appropriate HTTP status codes along with error messages in JSON format.