a JSON RESTful API created to manage the back-end features of a meditation app.
Table of Contents
The goal of the project is to deliver the back-end structure aimed to manage an hypothetical application dedicated to meditation. I used Node.js
(with Express
framework) and MongoDB
database for the purpose.
The API structure is made up of three data Schemas:
users
: data about app subscribersintervals
: timeframes during which users try to achieve their meditation goalsgoals
: the main topic of the meditation app, challenges that users try to win
Using the correct relevant endpoints you can interact with users, intervals and goals and create, read, update and delete them. Furthermore, you can search through intervals using queries and join any goal to an interval.
I used Node.js
to bootstrap this project. You can install it here.
Once installed, you are ready to go:
-
verify you installed Node.js correctly by checking its version on your computer
node -v
npm -v
-
clone this repository
git clone https://github.com/egidiosalinaro/meditActive-api
Once downloaded this repo, in the project directory, you can:
-
connect your MongoDB database
create a
.env
file (you won't find mine because it is in the.gitignore
list) containing an enviroment variable namedDB_URI
calling your MongoDB connection string (see theDB_URI
environment variable in action in the filedatabaseConnection.js
)
Example:DB_URI="mongodb+srv://...
-
install libraries and dependencies
npm install
-
test the app
npm test
-
run the app
npm start
You can use this API on the port 5000 via platforms like Postman, Thunderclient or Insomnia.
The first parameter of every path is the name of the app itself /meditactive
-
GET a list of all users from the database
/meditactive/users
-
add a new user to the database with a POST request
/meditactive/users
{ "name": "insert an alphanumeric string, min 2 characters", "surname": "insert an alphanumeric string, min 2 characters", "email": "insert a valid email" }
-
GET a specific user's details*
/meditactive/users/:id
-
update a user with a PUT request*
/meditactive/users/:id
-
DELETE a user from the database*
/meditactive/users/:id
*(:id must be a valid MongoDB id)
-
GET a list of all goals from the database
/meditactive/goals
-
add a new goal to the database with a POST request
/meditactive/goals
{ "title": "insert an alphanumeric string, min 2 characters", "description": "insert an alphanumeric string, min 2 characters", "days": "insert a number" }
-
GET a specific goal's details*
/meditactive/goals/:id
-
update a goal with a PUT request*
/meditactive/goals/:id
-
DELETE a goal from the database*
/meditactive/goals/:id
*(:id must be a valid MongoDB id)
-
GET a list of all intervals from the database
/meditactive/intervals
-
add a new interval to the database with a POST request
/meditactive/intervals
{ "user": "insert a valid mongoID related to an existing user", "starting": "insert a valid ISO date", "ending": "insert a valid ISO date" }
-
join an interval with a goal using a PUT request*
/meditactive/intervals/:id
{ "relatedGoal": "insert a valid mongoID related to an existing goal" }
-
GET a list of intervals filtered by queries
/meditactive/intervals/filter
Filter parameters:
- user: insert a valid mongoID related to the
user
field - start: insert a valid ISO date for the
starting
field - end: insert a valid ISO date for the
ending
field - goal: insert a valid mongoID related to the
relatedGoal
field
example:
/meditactive/intervals/filter?goal=6335c098bb3ddb89f54cd3d6&start=2023-10-01
- user: insert a valid mongoID related to the
-
GET a specific interval's details*
/meditactive/intervals/:id
-
update an interval with a PUT request*
/meditactive/intervals/:id
-
DELETE an interval from the database*
/meditactive/intervals/:id
*(:id must be a valid MongoDB id)
-
.env
file containing mongoDB key - functions to connect/disconnect to database via
mongoose
- app configuration
- logger
- security middleware
- initializing routes
- error handling middlewares
- server main file
- creating Schemas and models
- routes files
- intervals routes
- mongoose
find
method for filtering queries
- mongoose
- users routes
- goals routes
- adding
.next
to catch error middlewares if needed
- intervals routes
- testing all routes and errors with
jest
andsupertest
- final code cleaning and code consistency
Distributed under the MIT License. See LICENSE
for more information.