This api is made to work with the project named above built by a team consisting of UI/UX Web, React FrontEnd, and Backend developers
This api will provide the resources necessary on the React App to log in, out, and display data for users to use. The complete project is built in a two week period where the team collaborates to get all essential items connected to each other to make one app for the user.
Make sure to add a .env file with at least the following:
PORT=5000
NODE_ENV=development
DATABASE_URL=postgres://postgres:<postgres_password>@localhost:5432/<database_name_in_postgres>
JWT_SECRET=your secret here... you can convert it to any type of hash online if you like
Convert Secret or anything to hash -> Click Here!
- This will convert the secret to an MD5 Hash string
- You can use any hash generator online, just Google Hash Generator
Fieldname | Data Type |
---|---|
id | Primary Key - Int - Generated By Database |
fname | String - Required |
lname | String - Required |
String - Required | |
password | String - Required - Hashed/Encrypted upon signup |
Deployed to Heroku: Backend Api
Most endpoints receive and return JSON
Method | Endpoint | Description |
---|---|---|
POST | /api/auth/register | Creates a user. Requires First Name, Last Name, Email, Username, and Password. Returns the user id, username, and a token. |
POST | /api/auth/login | Logs user in taking the username and password provided. Returns User Id, Username, and Token. |
POST /api/auth/register
Receives
{
"fname": "Test",
"lname": "Tester",
"email": "[email protected]",
"username": "tester",
"password": "test123"
}
Returns
{
"user_id": 1,
"username": "tester",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwibmFtZSI6IkFsaWNlIiwiZW1haWwiOiJhbGljZUBnbWFpbC5jb20iLCJyb2xlcyI6WyJTVFVERU5UIl0sImlhdCI6MTU5MjYxODM4MiwiZXhwIjoxNTkyNjI1NTgyfQ.JCn_0iOCptEmJ7xIKBf4tOPHZanncar719n0mGdHiI8"
}
POST /api/auth/login
Receives
{
"username": "tester",
"password": "test123"
}
Returns
{
"user_id": 1,
"username": "tester",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwibmFtZSI6IkFsaWNlIiwiZW1haWwiOiJhbGljZUBnbWFpbC5jb20iLCJyb2xlcyI6WyJTVFVERU5UIl0sImlhdCI6MTU5MjYxODM4MiwiZXhwIjoxNTkyNjI1NTgyfQ.JCn_0iOCptEmJ7xIKBf4tOPHZanncar719n0mGdHiI8"
}
Method | URL | Description |
---|---|---|
GET | /api/users/:id | Returns profile info for user by id |
PUT | /api/users/:id | Updates user info for user by id. Users can only update their own data |
DELETE | /api/users/:id | Deletes user for user by id. Users can only delete their own account |
GET /api/users/:id
Returns
{
"id": 1,
"fname": "Test",
"lname": "Tester",
"email": "[email protected]",
"username": "tester",
"password": "test123"
}
PUT /api/users/:id
Receives (fields that do not change can be ommitted)
{
"fname": "Test",
"lname": "Tester",
"email": "[email protected]",
"username": "tester",
"password": "test123"
}
Returns
{
"id": 1,
"fname": "Test",
"lname": "Tester",
"email": "[email protected]",
"username": "tester"
}
DELETE /api/users/:id
Does not receive or return JSON
Returns
- Status: 204 = No Content