Build a REST API for managing a database of Pokémon
In this project, we will be building a REST API for managing a database of Pokémon. The API will allow users to retrieve a list of Pokémon, a single Pokémon by ID, and Pokémon by type. It will also include features such as adding, updating, and deleting Pokémon from the database.
Some of pokemon to use:
[
{
"id": 1,
"name": "Bulbasaur",
"type": ["Grass", "Poison"],
"gen": 1
},
{
"id": 2,
"name": "Squirtle",
"type": ["Water"],
"gen": 1
},
{
"id": 3,
"name": "Charmander",
"type": ["Fire"],
"gen": 1
}
] To get started, you can use the following code snippet to set up a basic REST API using a framework such as Express.js:
const express = require('express')
const app = express()
app.get('/pokemon', (req, res) => {
// Return a list of Pokémon from the database
})
app.get('/pokemon/:id', (req, res) => {
// Return a single Pokémon by ID from the database
})
app.post('/pokemon', (req, res) => {
// Add a new Pokémon to the database
})
app.put('/pokemon/:id', (req, res) => {
// Update a Pokémon by ID in the database
})
app.delete('/pokemon/:id', (req, res) => {
// Delete a Pokémon by ID from the database
})
app.listen(3000, () => console.log('API listening on port 3000')) This code sets up a basic REST API with routes for retrieving a list of Pokémon, a single Pokémon by ID, and adding, updating, and deleting Pokémon from the database. You can use this code snippet as a starting point to build the Pokémon REST API.