This is a back-end project that provides a RESTful API to manage a database of Pokemon. Users can consult, add, modify, and delete Pokemon entries. Additionally, users can create accounts, log in, and log out.
- Installation
- Dependencies
- API Endpoints
- Get All Pokemon
- Get Pokemon by ID
- Add a New Pokemon
- Update a Pokemon
- Delete a Pokemon
- Register new User
- Log In
- Log Out
- Examples
- Clone the repository:
git clone https://github.com/Adalab/modulo-4-evaluacion-final-bpw-ellisoalgo.git
- Navigate to the project directory:
cd modulo-4-evaluacion-final-bpw-ellisoalgo
- Install the dependencies:
npm install
- Start the server:
npm run dev
- Express
- JWT (jsonwebtoken)
- bcrypt
- dotenv
- cors
- Endpoint:
/pokemon
- Method:
GET
- Description: Retrieve all Pokemon from the database.
- Endpoint:
/pokemon/:id
- Method:
GET
- Description: Retrieve a single Pokemon by its ID.
- Endpoint:
/pokemon/addnew
- Method:
POST
- Description: Add a new Pokemon to the database.
- Request Body:
{
"name": "string",
"photo": "string",
"type": "string",
"weight": "number",
"height": "number"
}
- Endpoint:
/pokemon/update/:id
- Method:
PUT
- Description: Update an existing Pokemon by its ID.
- Request Body:
{
"name": "string",
"photo": "string",
"type": "string",
"weight": "number",
"height": "number"
}
- Endpoint:
/pokemon/delete/:id
- Method:
DELETE
- Description: Delete a Pokemon by its ID.
- Endpoint:
/signup
- Method:
POST
- Description: Create a new user account with encrypted password.
- Request Body:
{ "email": "string", "name": "string", "address": "string", "password": "string" }
### Log In
- **Endpoint:** `/login`
- **Method:** `POST`
- **Description:** Log in to an existing user account.
- **Request Body:**
```json
{
"email": "string",
"password": "string"
}
- Endpoint:
/logout
- Method:
POST
- Description: Log out of the current user session.
Get All Pokemon
{
fetch('/pokemon')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
Get Pokemon by ID
{
fetch('/pokemon/1')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
Add a New Pokemon
{
fetch('/pokemon/addnew', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Pikachu',
photo: 'url_to_photo',
type: 'Electric',
weight: 6.0,
height: 0.4
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
Update a Pokemon
{
fetch('/pokemon/update/1', {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Raichu',
photo: 'url_to_new_photo',
type: 'Electric',
weight: 30.0,
height: 0.8
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
Delete a Pokemon
{
fetch('/pokemon/delete/1', {
method: 'DELETE'
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
Register New User
{
fetch('/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'email@email.com',
name: 'newuser',
address: '123 Street',
password: 'password123'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
Log in
{
fetch('login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'newuser',
password: 'password123'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
Log out
{
fetch('/logout', {
method: 'POST'
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}