- After cloning / pulling the repo, make sure to run an
npm install
in the main directory - Create a
.env
file in the root directory with the following fields:
mongoURI=mongodb+srv://<username>:<password>@<mongodb-cluster-id>.mongodb.net/<database_name>?retryWrites=true&w=majority
jwtSecret=<some_jwt_secret>
Note: you can get the above mongoURI inside MongoDB Atlas dashboard. Navigate to your database and click on "connect." This should give you your mongoURI, from which you only need to paste in your password in the field <password>.
Also, the jwtSecret can be literally anything. Just keep it secret.
cd
intoclient
directory and runnpm install --global expo-cli
- Run
npm install
in the client folder to install the dependencies
For development, run npm run dev
inside the root directory. Download the Expo Go app, create an account and scan the QR code in your terminal.
To interact with todos in the database, you can make requests to this API. For these examples, I will use the hostname localhost
, as this is what you will use when testing this locally. In production, replace this with your domain/hostname.
I suggest using Postman or Insomnia. If you use Insomnia, I have included the collection in server/MAS-FPA.json
. You can import the collection into Insomnia by going to Preferences > Data > Import Data > From File
and select MAS-FPA.json
.
Users are stored in a database collection. At the moment, the only fields available for a user registration are:
- username (required)
- password (required)
- firstname (required)
- lastname (required)
All passwords are salted and hashed using bcrypt
.
- Description: Register a user
- Params: none
- Body: (JSON)
Example
{
"username": "test",
"password": "password",
"firstname": "first name",
"lastname": "last name"
}
- Returns: A JSON containing a token e.g.:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNjEzYmMwZjc4ZGQzN2Y2OGYzNWRiZmZmIn0sImlhdCI6MTYzMTMwNTk3NiwiZXhwIjoxNjMxNjY1OTc2fQ.SGbJFvTRDCFgc8luGDHdf_-gNkgV-r4woOxnZCKTG18"
}
- Description: Authenticate (login) a user
- Params: none
- Body: (JSON)
Example
{
"username": "test",
"password": "password"
}
- Returns: A JSON containing a token e.g.:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNjEzYmMwZjc4ZGQzN2Y2OGYzNWRiZmZmIn0sImlhdCI6MTYzMTMwNTk3NiwiZXhwIjoxNjMxNjY1OTc2fQ.SGbJFvTRDCFgc8luGDHdf_-gNkgV-r4woOxnZCKTG18"
}
- Description: Get the user from the token
- Headers:
x-auth-token
This is the JWT you would get from registering or logging a user in. For example:
x-auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNjEzYmMwZjc4ZGQzN2Y2OGYzNWRiZmZmIn0sImlhdCI6MTYzMTMwNTk3NiwiZXhwIjoxNjMxNjY1OTc2fQ.SGbJFvTRDCFgc8luGDHdf_-gNkgV-r4woOxnZCKTG18
- Params: none
- Body: none
- Returns: A JSON containing a token e.g.:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNjEzYmMwZjc4ZGQzN2Y2OGYzNWRiZmZmIn0sImlhdCI6MTYzMTMwNTk3NiwiZXhwIjoxNjMxNjY1OTc2fQ.SGbJFvTRDCFgc8luGDHdf_-gNkgV-r4woOxnZCKTG18"
}
- Headers:
x-auth-token
with value JWT token - Description: GET all todos in the database with option to limit how many are returned.
- Params: None
- Body: (optional) Provide a
limit
field to limit the number of objects returned. Example:
{
"limit": 2
}
- Returns: Array of todo/task JSONs. Contains _id, name, created date, and (optional) description. e.g.:
[
{
"_id": "613c3c3771b0a39c97ad7e2c",
"name": "Work on MAS-FPA",
"description": "Add authentication to the project",
"user": "613bc0f78dd37f68f35dbfff",
"created": "2021-09-11T05:18:47.786Z",
"__v": 0
},
{
"_id": "613c430162ab24dbcdd1d6ab",
"name": "Complete my homework",
"description": "i have 10 assignments due by Friday night. Finish assignments 2, 3, 6, and 7 first.",
"user": "613bc0f78dd37f68f35dbfff",
"created": "2021-09-11T05:47:45.902Z",
"__v": 0
}
]
- Headers:
x-auth-token
with value JWT token - Description: Get a single todo by id. Id is auto-generated by mongo.
- Params: (required) id | Example:
GET http://localhost:5000/api/todo/613b9c267bc365e9e79954d1
- Body: none
- Returns: A single todo JSON with provided id e.g.:
{
"_id": "613c3c3771b0a39c97ad7e2c",
"name": "Work on MAS-FPA",
"description": "Add authentication to the project",
"user": "613bc0f78dd37f68f35dbfff",
"created": "2021-09-11T05:18:47.786Z",
"__v": 0
}
-
Headers:
x-auth-token
with value JWT tokenContent-Type
with valueapplication/json
-
Description: Create a new todo
-
Params: none
-
Body: (json)
-
(required) name
-
(optional) description
-
Example
-
{
"name": "Complete my homework",
"description": "i have 10 assignments due by Friday night. Finish assignments 2, 3, 6, and 7 first."
}
- Returns: A JSON containing the todo along with a
msg
field stating it was successful:
e.g.:
{
"msg": "Todo successfully created",
"todo": {
"name": "Complete my homework",
"description": "i have 10 assignments due by Friday night. Finish assignments 2, 3, 6, and 7 first.",
"user": "613bc0f78dd37f68f35dbfff",
"_id": "613c430162ab24dbcdd1d6ab",
"created": "2021-09-11T05:47:45.902Z",
"__v": 0
}
}
- Headers:
x-auth-token
with value JWT tokenContent-Type
with valueapplication/json
- Description: Update a single todo, by id
- Params: (required) id | Example:
PUT http://localhost:5000/api/todo/613b9c267bc365e9e79954d1
- Body: (json)
- (required) name
- (optional) description
- Example:
{
"name": "Become the president... later",
"description": "Run for president in 2028"
}
- Returns: A single todo JSON with provided id e.g.:
{
"msg": "Updated todo",
"todo": {
"name": "Become the president... later",
"description": "Run for president in 2028"
}
}
- Headers:
x-auth-token
with value JWT token - Description: Delete a single todo by id.
- Params: (required) id | Example:
DELETE http://localhost:5000/api/todo/613b9c267bc365e9e79954d1
- Body: none
- Returns: A single todo JSON with a message informing successful deletion of todo. e.g.:
{
"msg": "Todo removed"
}