Deployed on Heroku with a PosgresSQL database https://wunderlist-02.herokuapp.com/
This project is a RESTful API built using Node and Express. The purpose of this project is to provide a Backend for a Wunderlist 2.0 web application. User registration, login, todo creation, deletion, fetching, or editing, are all handled here. This project was deployed on Heroku
.
- The server is run using Node.
- Express is a minimalist Node web application framework for building APIs.
- PostgreSQL is the database used for production. SQLite3 was used for development and testing.
- Knex is a SQL query builder for JavaScript.
- Knex Cleaner is a Knex dependency for cleaning up seed data.
- Jsonwebtoken is used for authenticating users.
- Bcrypt is used for hashing passwords.
- Helmet adds a base layer of security by hiding basic info about the API when interacting with it.
- Dotenv allows the server to interact with environment variables.
- Cors is a dependency used to allow Cross Origin Resource Sharing. This allows the Frontend client to interact with the Backend.
- Cross-env allows the developer to set environment variables in a script.
- Jest is the library used for writing tests.
- Supertest is the dependency used for making "requests" in jest tests.
- Node
- Express
- PostgreSQL (Production)
- SQLite3 (Development)
- Knex
- Knex Cleaner
- Bcryptjs
- Jsonwebtoken
- Cors
- Helmet
- Dotenv
- Faker
- Nodemon (Development)
- Cross-Env (Development)
- Jest (Development)
- Supertest (Development)
Install dependencies
yarn install
Run database migrations
yarn knex migrate:latest
Run database seeds
yarn knex seed:run
Run tests
yarn test
Run the server
yarn server
If you would like to make a request to the todos or users endpoint, a valid JSON web token is required in your request headers.authorization. This token is acquired by successfully registering an account or logging in. Also, for testing to run successfully you will have to remove the authentication piece of middleware from the todos route in the server.js file.
POST /api/auth/register
Name | Type | Description |
---|---|---|
username | String | Users username |
password | String | Users password |
firstName | String | Users firstName |
lastName | String | Users lastName |
POST https://wunderlist-02.herokuapp.com/api/auth/register
will create a new user and send back a token. Username, password, firstName, lastName are required fields.
Register example:
axios.post('/api/auth/register', {
"username": "harry",
"password": "potter",
"firstName": "harry",
"lastName" : "potter"
});
Register Success
{
"message": "Welcome harry!",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzMsInVzZXJuYW1lIjoiaGFycnkiLCJpYXQiOjE1NjE1NzIzMTksImV4cCI6MTU2MjE3NzExOX0.VCaGen64x_WEkVueJof8XKZxOImjxK09tNN6tiYSZZw",
"userID": 33
}
Error Example:
ERROR 500
{
"status": 500,
"message": "Your user could not be created ${error}."
}
POST /api/auth/login
Name | Type | Description |
---|---|---|
username | String | Users username |
password | String | Users password |
POST https://wunderlist-02.herokuapp.com/api/auth/login
will log the user in, and send back a token. Username and password required.
Login example:
axios.post('/api/auth/login', {
username:"hermione",
password: "granger"
});
Login Success
{
"message": "Welcome hermione!",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzMsInVzZXJuYW1lIjoiaGVybWlvbmUiLCJpYXQiOjE1NjE0MTU2OTQsImV4cCI6MTU2MjAyMDQ5NH0.rwTCYJ97VA7IvxT0D2uwY3yHljUr0EPNlKQv-P8HloQ",
"userID": 33
}
Error Example:
ERROR 401
{
"status": 401,
"message": "Username or password is incorrect"
}
GET https://wunderlist-02.herokuapp.com/api/todos/
will return an array of todos.
GET https://wunderlist-02.herokuapp.com/api/todos/:id
will return an object corresponding to the todo at that ID.
POST https://wunderlist-02.herokuapp.com/api/todos/
will add a new todo, and return the created object. title, task and setDate are required fields. user_id, notes, and completed are optional fields.
DEL https://wunderlist-02.herokuapp.com/api/todos/:id
will delete the todo at this ID, and return the deleted object.
PUT https://wunderlist-02.herokuapp.com/api/todos/:id
will edit the todo at this ID, and return the edited object.
GET https://wunderlist-02.herokuapp.com/api/users/:id
allows a user to view their specific profile by id
PUT https://wunderlist-02.herokuapp.com/api/users/:id
allows a user to edit their specific profile
DELETE https://wunderlist-02.herokuapp.com/api/users/:id
allows a user to delete their specific profile
If you are running the project locally, every endpoint here is the same, but the heroku URL is replaced with http://localhost:4000/
. For example, GET
http://localhost:4000/api/todos
will return an array of todos.