Pokevault is an API for managing a collection of Pokemon, allowing players to buy, sell, and view details about their Pokemon. This documentation provides details on the available endpoints and how to use them.
To get started with the Pokevault API, follow these steps:
- Clone the repository.
- Install dependencies using
npm install
. - Set up the database by running migrations with
npm run migrate
. - Start the server with
npm start
. - Explore the API endpoints detailed below.
POST /players/register
POST /players/login
POST /players/profile
GET /pokemons
GET /pokemons/:id
GET /mypokemons
POST /mypokemons/gacha
DELETE /mypokemons/:id
POST /orders/topup
POST /orders/pay
Profile information of the authenticated player.
Headers: Authorization: Bearer token
{
"accessToken":"example_token"
}
Success Response:
Response: (200 - OK)
{
"id": 1,
"username": "Example",
"email": "[email protected]",
"balance": 0,
"createdAt": "2024-01-18T14:08:21.561Z",
"updatedAt": "2024-01-19T05:33:04.735Z"
}
Error Response:
Response: (404 - Not Found)
{
"message": "NotFoundError",
}
Register new player for player authentication.
Body:
{
"username": "Example",
"email": "[email protected]",
"password": "12345"
}
Success Response:
Response: (201 - Created)
{
"message": "Register Successful",
"username": "example",
"email": "[email protected]"
}
Error Response:
Response: (400 - Bad Request)
{
"message": "Username is required"
}
OR
{
"message": "Email is required"
}
OR
{
"message": "Invalid email format"
}
OR
{
"message": "Password is required"
}
Response: (401 - Unauthorized)
{
"message": "Email already registered"
}
Player authentication.
Body:
{
"email": "[email protected]",
"password": "12345"
}
Success Response:
Response: (200 - OK)
{
"accessToken":"example_token"
}
Error Response:
Response: (400 - Bad Request)
{
"message": "Email is required"
}
OR
{
"message": "Password is required"
}
Response: (401 - Unauthorized)
{
"message": "Authentication failed"
}
Get a list of all Pokemon.
Success Response:
Response: (200 - OK)
"pokemons":
[
{
"id": 1,
"name": "bulbasaur",
"image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png",
"attack": 49,
"defense": 49,
"hp": 45,
"speed": 45,
"level": 1,
"type": "grass, poison",
"rarity": "Uncommon",
"createdAt": "2024-01-18T04:26:01.787Z",
"updatedAt": "2024-01-18T04:26:01.787Z"
},
]
Display Pokemon details based id
.
Params:
{
"id": integer
}
Success Response:
Response: (200 - OK)
{
"id": 1,
"name": "bulbasaur",
"image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png",
"attack": 49,
"defense": 49,
"hp": 45,
"speed": 45,
"level": 1,
"type": "grass, poison",
"rarity": "Uncommon",
"createdAt": "2024-01-18T04:26:01.787Z",
"updatedAt": "2024-01-18T04:26:01.787Z"
}
Error Response:
Response: (404 - Not found)
{
"message": "Not found"
}
Get the Pokemon that the player has.
Headers: Authorization: Bearer token
{
"accessToken":"example_token"
}
Success Response:
Response: (200 - OK)
- If Don't have any Pokemon
[]
- If Have any Pokemon
[
{
"PlayerId": 2,
"PokemonId": 49,
"Pokemon": {
"name": "venomoth",
"image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/49.png",
"attack": 65,
"defense": 60,
"hp": 70,
"speed": 90,
"level": 1,
"type": "bug, poison",
"rarity": "Rare"
}
},
{
"PlayerId": 2,
"PokemonId": 52,
"Pokemon": {
"name": "meowth",
"image": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/52.png",
"attack": 45,
"defense": 35,
"hp": 40,
"speed": 90,
"level": 1,
"type": "normal",
"rarity": "Uncommon"
}
},
]
Gacha to get Pokemon randomly.
Headers: Authorization: Bearer token
{
"accessToken":"example_token"
}
Success Response:
Response: (201 - Created)
{
"message": "Gacha successful.",
"newBalance": 0,
"acquiredPokemon": {
"id": 648,
"name": "meloetta-aria",
"attack": 77,
"defense": 77,
"hp": 100,
"speed": 90,
"type": "normal, psychic",
"rarity": "Legendary"
}
}
Error Response:
Response: (400 - Bad Request)
{
"message": "InsufficientBalanceError"
}
Response: (404 - Not found)
{
"message": "Not found"
}
Delete owned pokemon based on id
.
Headers: Authorization: Bearer token
{
"accessToken":"example_token"
}
Params:
{
"id": integer
}
Success Response:
Response: (201 - Created)
{
"message": "Deleted"
}
Error Response:
Response: (404 - Not found)
{
"message": "Not found"
}
Do an initial Midtrans to make an order for how much balance want to add to the player.
Headers: Authorization: Bearer token
{
"accessToken":"example_token"
}
body:
{
"amount": integer
}
Success Response:
Response: (200 - OK)
{
"token": "example_token_order",
"redirect_url": "example_midtrans_url"
}
Error Response:
Response: (400 - Bad Request)
{
"message": "Amount is required"
}
Make status and balance changes after Midtrans payments based on token
.
Headers: Authorization: Bearer token
{
"accessToken":"example_token"
}
body:
{
"token": "example_token_order",
"transaction_status": "capture",
"fraud_status": "accept"
}
Success Response:
Response: (201 - Created)
{
"message": "Payment status updated"
}
Response: (500 - Internal Server Error)
{
"message": "Internal Server Error"
}
The project uses the following dependencies:
- Express
- Sequelize
- Bcrypt
- Jsonwebtoken
- Jest & Supertest (for testing)
- Axios (for Poke API integration)
Install them using npm install
.
The Poke API is used to fetch details about Pokemon, including names, images, stats, and more. Visit the Poke API documentation for more information.
Midtrans is integrated to handle payment transactions for player balance top-up. Visit the Midtrans documentation for more information on integrating Midtrans into your application.