API for the While (true) Play website. While (true) Play is a mock store website for games. This API was built using NodeJS, Express and MongoDB to manage transaction users, games and orders.
It was the 14ᵗʰ project developed during the Driven Full Stack Bootcamp in pairs (see contributors in the end).
- Authentication routes for registering and logging in
- Users created with an encrypted password and persisted to the database
- Password strength validation
- User session persisted to the database and validated with JWT via middleware
- Games search with queries strings such as filter, order, limit
- Game search via id with view increment for each request
- Order confirmation via email with SendGrid (it doesn't have payment support since it's just a mock project)
- Responsabilities divided between routes and controllers
- All data stored on a MongoDB database
- All the entries are validated against schemas
{
"title": string,
"images": {
"cover": string,
"screenshots": string[]
},
"description": string,
"genre": string[],
"views": number,
"price": number,
"reviews": string[],
"id": number,
"amountSold": number,
"discountAmount": number,
"hasDiscount": boolean,
"releaseDate": Date
}
Ps: most of the times this data will be just passed along the application
-
POST /sign-up
Body Type Description name
string
Required - Valid name email
string
Required - Valid email password
string
Required - Valid password password length: from 6 to 20 characters
{ "name": "string", "email": "string", "password": "string" }
-
POST /sign-in
Body Type Description email
string
Required - Valid email password
string
Required - Valid password password length: from 6 to 20 characters
{ "email": "string", "password": "string" }
"token string"
-
GET /user
Name Description authorization
Required - "Bearer {{token}}" { "name": "string", "email": "string", "image": "string", "games": "Game[]" }
Game[] is an array of Game objects. See the section "Models" for more information
-
POST /cart
Body Type Description game
Game
Required - Game model { "_id":"627b0e140e66b143feacb54f", "title":"Elden Ring", "images":{ "cover":"https://cdn.akamai.steamstatic.com/steam/apps/1245620/capsule_616x353.jpg?t=1649774637", "screenshots": [ "https://cdn.akamai.steamstatic.com/steam/apps/1245620/ss_e80a907c2c43337e53316c71555c3c3035a1343e.600x338.jpg?t=1649774637", "https://cdn.akamai.steamstatic.com/steam/apps/1245620/ss_ae44317e3bd07b7690b4d62cc5d0d1df30367a91.600x338.jpg?t=1649774637" "https://cdn.akamai.steamstatic.com/steam/apps/1245620/ss_1011610a0e330c41a75ffd0b3a9a1bac3205c46a.600x338.jpg?t=1649774637" ] }, "description":"THE NEW FANTASY ACTION RPG. Rise, Tarnished, and be guided by grace to brandish the power of the Elden Ring and become an Elden Lord in the Lands Between.", "genre":[ "Action", "RPG" ], "views":460, "price":249.9, "reviews":[], "id":4, "amountSold":27, "discountAmount":0, "hasDiscount":"false", "releaseDate":"2022-02-24T00:00:00-03:00" }
Name Description authorization
Required - "Bearer {{token}}"
-
GET /games
Parameter Type Description q
string
FIlter query limit
number
Limit response amount order
enum
desc
orasc
[ { "_id": "627b0e140e66b143feacb54b", "title": "Project Zomboid", "images": { "cover": "https://www.mobygames.com/images/covers/l/326473-project-zomboid-linux-front-cover.jpg", "screenshots": [ "https://images.gog-statics.com/756e29173677fafc8dd206623f74582a076b17d2dce1021d093c658d43cd4b73.jpg", "https://images.gog-statics.com/6dcf744d35a5623741c7607cdf07b587388b05234346cd262a19973a6c4d9370.jpg", "https://images.gog-statics.com/ecbbfb41e8035bbe199af981c04703742efba60c0bfd3f591dcf131ec7fbb665.jpg" ] }, "description": "Project Zomboid is an open-ended zombie-infested sandbox. It asks one simple question – how will you die?\nIn the towns of Muldraugh and West Point, survivors must loot houses, build defences and do their utmost to delay their inevitable death day by day. No help is coming – their continued survival relies on their own cunning, luck and ability to evade a relentless horde.", "genre": [ "Action", "Simulation", "Open World" ], "views": 192, "price": 37.99, "reviews": [], "id": 0, "amountSold": 21, "discountAmount": 0.33, "hasDiscount": true, "releaseDate": "2023-11-08T00:00:00-03:00" } ]
-
GET /games/{id}
Parameter Description id
Required - Game id PS: You must pass the game id property, not _id
{ "_id": "627b0e140e66b143feacb54b", "title": "Project Zomboid", "images": { "cover": "https://www.mobygames.com/images/covers/l/326473-project-zomboid-linux-front-cover.jpg", "screenshots": [ "https://images.gog-statics.com/756e29173677fafc8dd206623f74582a076b17d2dce1021d093c658d43cd4b73.jpg", "https://images.gog-statics.com/6dcf744d35a5623741c7607cdf07b587388b05234346cd262a19973a6c4d9370.jpg", "https://images.gog-statics.com/ecbbfb41e8035bbe199af981c04703742efba60c0bfd3f591dcf131ec7fbb665.jpg" ] }, "description": "Project Zomboid is an open-ended zombie-infested sandbox. It asks one simple question – how will you die?\nIn the towns of Muldraugh and West Point, survivors must loot houses, build defences and do their utmost to delay their inevitable death day by day. No help is coming – their continued survival relies on their own cunning, luck and ability to evade a relentless horde.", "genre": [ "Action", "Simulation", "Open World" ], "views": 192, "price": 37.99, "reviews": [], "id": 0, "amountSold": 21, "discountAmount": 0.33, "hasDiscount": true, "releaseDate": "2023-11-08T00:00:00-03:00" }
POST /checkout
Body | Type | Description |
---|---|---|
Array |
Required - Array of Game models |
[
{
"_id":"627b0e140e66b143feacb54f",
"title":"Elden Ring",
"images":{
"cover":"https://cdn.akamai.steamstatic.com/steam/apps/1245620/capsule_616x353.jpg?t=1649774637",
"screenshots":
[
"https://cdn.akamai.steamstatic.com/steam/apps/1245620/ss_e80a907c2c43337e53316c71555c3c3035a1343e.600x338.jpg?t=1649774637",
"https://cdn.akamai.steamstatic.com/steam/apps/1245620/ss_ae44317e3bd07b7690b4d62cc5d0d1df30367a91.600x338.jpg?t=1649774637"
"https://cdn.akamai.steamstatic.com/steam/apps/1245620/ss_1011610a0e330c41a75ffd0b3a9a1bac3205c46a.600x338.jpg?t=1649774637"
]
},
"description":"THE NEW FANTASY ACTION RPG. Rise, Tarnished, and be guided by grace to brandish the power of the Elden Ring and become an Elden Lord in the Lands Between.",
"genre":[
"Action", "RPG"
],
"views":460,
"price":249.9,
"reviews":[],
"id":4,
"amountSold":27,
"discountAmount":0,
"hasDiscount":"false",
"releaseDate":"2022-02-24T00:00:00-03:00"
}
]
Clone the project:
git clone https://github.com/lemoscaio/while-true-play-api.git
Go to the project directory:
cd while-true-play-api
Install dependencies:
npm install
Set up the environment variables in the .env
file, using the .env.example
.
Make sure the MongoDB server is running and available.
Start the server:
node index.js
In this project I learned the following:
- to build a store and manipulate data such as how to manage user cart
- to use JWT