Node.js API server for Mood Minder.
- Clone the repository:
git clone https://github.com/mhanki/Mood-Minder-API.git
- Install the dependencies:
npm install
- Set up a MySQL database. You can find the schema in the
schema.sql
file. - Optionally populate the database with the feelings and environments data found in
seed.sql
. - Configure your connection details in
db.js
if needed.
To start the API server, run:
npm start
By default, the server will run on port 8000. You can access the API at http://localhost:8000.
Users & Auth
POST /users
: Create a new user.POST /auth
: Generate a JWT token by providing valid credentials.
Feelings & Environments
GET /feelings
: Retrieves all feeling entries.GET /feelings/:id
: Retrieves a specific feeling.GET /environments
: Retrieves all environments entries.GET /environments/:id
: Retrieves a specific environment.
Logs (Protected routes, require authentication)
GET /logs
: Retrieves all user logs.GET /logs/:id
: Retrieves a specific log.POST /logs
: Creates a new log.PUT /logs/:id
: Updates a specific log.DELETE /logs/:id
: Deletes a specific log.
Posts (Protected routes, require authentication)
GET /posts
: Retrieves all user posts.GET /posts/:id
: Retrieves a specific post.POST /posts
: Creates a new post.PUT /posts/:id
: Updates a specific post.DELETE /posts/:id
: Deletes a specific post.
Register a new user
POST /users
content-type: application/json
{
"name": "Jane",
"username": "Jane123",
"email": "[email protected]",
"password": "123"
}
Login and create a JWT token
Requeset
POST /auth
content-type: application/json
{
"email": "[email protected]",
"password": "123"
}
Response
Status: 200 OK
content-type: application/json
{
"token": "<JWT_TOKEN>",
"email": "[email protected]",
"password": "123"
}
Retrieve all feelings
Request
GET /feelings
Response
Status: 200 OK
content-type: application/json
[
{
"ID": 1,
"name": "horrible",
"rank": 1
},
{
"ID": 2,
"name": "terrible",
"rank": 2
},
]
Retrieve all environments
Request
GET /environments
Response
Status: 200 OK
content-type: application/json
[
{
"ID": 1,
"name": "at work"
},
{
"ID": 2,
"name": "outdoors"
},
]
Retrieve all user logs (protected route)
GET /logs
Authorization: Bearer <JWT_TOKEN>
Retrieve a specific log (protected route)
GET /logs/:id
Authorization: Bearer <JWT_TOKEN>
Add a log (protected route)
POST /logs
content-type: application/json
Authorization: Bearer <JWT_TOKEN>
{
"feeling": "<FEELING_ID>",
"environment": "<ENVIRONMENT_ID>"
}
Get a specific post (protected route)
Request
GET /posts/1
Authorization: Bearer <JWT_TOKEN>
Response
Status: 200 OK
content-type: application/json
{
"post": {
"ID": 1,
"content": "New Post",
"is_private": 1,
"created_at": "2023-03-01T06:17:25.000Z",
"updated_at": null,
"user_id": 17
}
}
Add a post (protected route)
POST /posts
content-type: application/json
Authorization: Bearer <JWT_TOKEN>
{
"content": "A new post",
"isPrivate": 0
}
Found a bug or have a concrete feature request? Open a corresponding issue through the Issues Tab.
This project is licensed under the MIT License. See the LICENSE file for more information.