Contact list is an API that consists of creating users and their respective contacts..
These were the main technologies used in this project:
- Ricardo Martins - Dev
Some routes need authentication. The authentication used is the Bearer Token type.
The token is generated automatically at user login.
Thus, to access routes with authentication, it is necessary to have a user and be logged in with the user.
Also, some routes require the user to be an admin, user, or owner of the contact.
Please read each route's documentation to understand which authentications are required.
The User object is defined as:
Field | Type | Description |
---|---|---|
id | string | User's unique identifier |
name | string | User name * |
string | User email * | |
phone | string | Contact Phone * |
password | string | User password * |
isAdm | boolean | Defines whether a user is an administrator or not |
createdAt | string | Date when the user was created |
Method | Routes | Description |
---|---|---|
POST | /users | Create user |
GET | /users | List all users |
GET | /users/:id | Lists a user using its ID as a parameter |
PATCH | /user/:id | Update user |
DELETE | /delete/:id | Delete user |
- POST /users
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: None
- Content-type: application/json
{
"name": "Ricardo",
"email": "[email protected]",
"phone": "0xx 9xxxx-xxxx",
"password": "1234",
"isAdm": true
}
{
{
"id": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
"name": "Ricardo",
"email": "[email protected]",
"phone" : "0xx 9xxxx-xxxx",
"isAdm": true,
"createdAt": "2022-10-29T00:41:28.717Z",
}
}
{
"message": "This email already exists"
}
- GET /users
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: Bearer Token
- Content-type: application/json
- Empty body
- User must be an Adm
{
"authorization": "Bearer Token"
}
{
[
{
"id": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
"name": "Ricardo",
"email": "[email protected]",
"phone" : "0xx 9xxxx-xxxx",
"isAdm": true,
"createdAt": "2022-10-29T00:41:28.717Z",
}
...
]
}
{
"message": "Missing authorization token"
}
{
"message": "User is not an admin"
}
- GET /users/:id
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: Bearer Token
- Content-type: application/json
- Empty body
- User must be an Adm or User common
{
"authorization": "Bearer Token"
}
{
{
"id": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
"name": "Ricardo",
"email": "[email protected]",
"phone" : "0xx 9xxxx-xxxx",
"isAdm": true,
"createdAt": "2022-10-29T00:41:28.717Z",
"contacts": []
}
}
{
"message": "Missing authorization token"
}
- PATCH /users/:id
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: Bearer Token
- Content-type: application/json
- User must be an Adm and common User
{
"authorization": "Bearer Token"
}
{
{
"name": "Ricardo Martins",
"phone" : "0xx 98xxx-xxxx",
"email": "[email protected]",
}
}
{
"message": "Missing authorization token"
}
{
"message": "Only admin can update or delete other users"
}
- DELETE /users/:id
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: Bearer Token
- Content-type: application/json
- User must be an Adm and common User
{
"authorization": "Bearer Token"
}
No body returned for response
{
"message": "Missing authorization token"
}
{
"message": "Only admin can update or delete other users"
}
{
"message": "User already deleted"
}
{
"message": "User not found"
}
The User object is defined as:
Field | Type | Description |
---|---|---|
id | string | Contact unique identifier |
name | string | Contact name * |
string | Contact email * | |
phone | string | Contact Phone * |
user | string | Defines which user owns this contact |
createdAt | string | Date when the contact was created |
Method | Routes | Description |
---|---|---|
POST | /contacts | Create contacts |
GET | /contacts | List all contacts |
PATCH | /contacts/:id | Update contacts |
DELETE | /contacts/:id | Delete contacts |
- POST /contacts
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: None
- Content-type: application/json
{
"name": "Guilherme",
"email": "[email protected]",
"phone": "0xx 9xxxx-xxxx",
}
{
{
"id": "341f4ee4-8d77-4866-bf47-8d3e32d531e8",
"name": "Guilherme Martins",
"email": "[email protected]",
"phone": "11999897898",
"user": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
"createdAt": "2023-02-08T03:23:20.977Z"
}
}
{
"message": "You already have this contact"
}
- GET /contacts
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: Bearer Token
- Content-type: application/json
- Empty body
- User must be an Adm
{
"authorization": "Bearer Token"
}
{
[
{
"id": "341f4ee4-8d77-4866-bf47-8d3e32d531e8",
"name": "Guilherme Martins",
"email": "[email protected]",
"phone": "11999897898",
"user": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
"createdAt": "2023-02-08T03:23:20.977Z"
}
...
]
}
{
"message": "Token required."
}
{
"message": "User is not an admin"
}
- PATCH /contacts/:id
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: Bearer Token
- Content-type: application/json
- User must be an Adm and common User
{
"authorization": "Bearer Token"
}
{
{
"name": "Guilherme Martins",
"phone" : "0xx 97xxx-xxx2",
"email": "[email protected]",
}
}
{
"message": "Token required"
}
{
"message": "You can only edit your own contact"
}
{
"message": "This contact dont exist"
}
- DELETE /contacts/:id
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: Bearer Token
- Content-type: application/json
- User must be an Adm and common User
{
"authorization": "Bearer Token"
}
No body returned for response
{
"message": "Missing authorization token"
}
{
"message": "You can only update or delete your own contact"
}
{
"message": "Contact not found"
}
The Session object is defined as:
Field | Type | Description |
---|---|---|
string | Registered user email | |
password | string | Registered user password |
Method | Routes | Description |
---|---|---|
POST | /sessions | Create user |
- POST /sessions
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: None
- Content-type: application/json
{
"email": "[email protected]",
"password": "123456"
}
{
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc4NWFjMDRmLWE4NWMtNGJlMy05YTc5LTY3NmFjYzZhYmUyYiIsImlzQWRtIjp0cnVlLCJpYXQiOjE2NzU4MjQyMDQsImV4cCI6MTY3NTkxMDYwNCwic3ViIjoiNzg1YWMwNGYtYTg1Yy00YmUzLTlhNzktNjc2YWNjNmFiZTJiIn0.2Fwg3Fl4DBJcbZyR3mMSyJ76wV7BI-HQrCGZBYQYdX8"
}
}
{
"message": "Invalid user or password"
}
Method | Routes | Description |
---|---|---|
GET | /profile | Get all data from the user who owns the token |
- GET /profile
- Host: https://cine-express-projeto-m4.herokuapp.com
- Authorization: Bearer Token
- Content-type: application/json
{
{
"id": "7fd311fe-f80a-465e-9ed9-8bb4e28bbf45",
"name": "Ricardo",
"email": "[email protected]",
"phone" : "0xx 9xxxx-xxxx",
"isAdm": true,
"createdAt": "2022-10-29T00:41:28.717Z",
"contacts": []
}
}
In the project directory, you can run: