NOTE! Token expiration time is moved/added to .env
file. Check .env.sample
NOTE #2! When publishing application on real server, you need to update your client to connect to your public server address instead of localhost:3000
!
Node.js + Express application.
(Check week/feature branches too.)
- Clone/download code
- Run
npm i
inside project folder - Install & start MySQL/MariaDB server
- Import database script(s) in
db/
folder - Create
.env
file based on.env.sample
- Start the dev server:
npm run dev
/npm start
GET http://127.0.0.1:3000/items
GET http://127.0.0.1:3000/items/:id
DELETE http://127.0.0.1:3000/items/:id
POST http://127.0.0.1:3000/items
content-type: application/json
body: {"name": "New Item"}
Example queries:
# Login
POST http://localhost:3000/api/users/login
content-type: application/json
{
"username": "user",
"password": "secret"
}
## Get user by token (requires token)
GET http://localhost:3000/api/auth/me
Authorization: Bearer <token>
Example queries:
# Get all users (requires token)
GET http://127.0.0.1:3000/api/users
Authorization: Bearer <token>
# Get user by id (requires token)
GET http://127.0.0.1:3000/api/users/:id
Authorization: Bearer <token>
# Delete user (requires token)
DELETE http://127.0.0.1:3000/api/users/:id
Authorization: Bearer <token>
# Create user (register)
POST http://127.0.0.1:3000/api/users
content-type: application/json
{
"username": "test-update4",
"password": "test-pw-update4",
"email": "update4@example.com"
}
# Update user's own data (requires token)
PUT http://127.0.0.1:3000/api/users/
Authorization: Bearer <token>
content-type: application/json
{
"username": "test-update4",
"password": "test-pw-update4",
"email": "update4@example.com"
}
Example queries:
# Get all entries for a logged in user (requires token)
GET http://localhost:3000/api/entries
Authorization: Bearer <token>
# Get entries by id
GET http://localhost:3000/api/entries/:id
# Post entry
POST http://localhost:3000/api/entries
content-type: application/json
{
"entry_date": "2024-02-12",
"mood": "Happy",
"weight": 69.6,
"sleep_hours": 7,
"notes": "This was a good day",
"user_id": 3
}
# Update entry
PUT http://localhost:3000/api/entries/:id
content-type: application/json
{
"entry_date": "2024-02-12",
"mood": "Even more happy now",
"weight": 69.6,
"sleep_hours": 7,
"notes": "This was a good day",
"user_id": 3
}
# Delete entry
DELETE http://localhost:3000/api/entries/:id