Skip to content

Conversation

@Jonash189
Copy link

@Jonash189 Jonash189 commented Dec 4, 2024

https://jonas-project-express-api.onrender.com/

Root endpoint: Provides API documentation with a list of available endpoints and their descriptions.

https://jonas-project-express-api.onrender.com/boardgames

Returns a collection of all boardgames available in the API.

https://jonas-project-express-api.onrender.com/category?category=Strategy

Filters and returns boardgames that belong to the specified category ('Strategy' in this example).

https://jonas-project-express-api.onrender.com/maxPlayers?maxPlayers=4

Filters and returns boardgames that can be played by the specified maximum number of players (4 in this example).

https://jonas-project-express-api.onrender.com/boardgames/1

Returns details of a specific boardgame based on its unique ID (1 in this example).

- Set up Express server with CORS and JSON parsing middleware.
- Added a root endpoint (/) that provides API documentation with available endpoints.
- Implemented a GET endpoint (/boardgames) to return all boardgames.
- Implemented a GET endpoint (/category) to filter boardgames by category using query parameters.
- Implemented a GET endpoint (/maxPlayers) to filter boardgames by maximum number of players using query parameters.
- Implemented a GET endpoint (/boardgames/:id) to retrieve a specific boardgame by its unique ID.
- Enhanced error handling for cases where data is not found or invalid parameters are provided.
- Included robust filtering and querying functionality for better usability.
- Verified and tested all endpoints to ensure correct functionality and consistency.
Copy link
Contributor

@HIPPIEKICK HIPPIEKICK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job with your first API Jonas! For coming weeks, please remember that endpoints should be named after what they return (so all filtering/sorting can happen in the /boardgames route in this case, since you're returning boardgames). Nice to see that you did some extra filtering though ⭐

Comment on lines +13 to +22
res.json({
message: "Welcome to the Jonas boardgames API! Choose from the endpoints below:",
endpoints: {
"/boardgames": "Explore all boardgames",
"/category?category=<category>": "Get all boardgames by category",
"/maxPlayers?maxPlayers=<number>": "Get all boardgames by maximum number of players",
"/boardgames/:id": "Get a single boardgames by ID"
}
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Express List Endpoints is a great package so you don't have to update your docs manually

Comment on lines +30 to +51
app.get("/category", (req, res) => {
const category = req.query.category;
const filteredGames = boardgames.filter(game =>
game.category.toLowerCase() === (category || "").toLowerCase()
);
res.json(filteredGames);
});

// Return all boardgames with a specific maximum number of players
app.get("/maxPlayers", (req, res) => {
const maxPlayers = parseInt(req.query.maxPlayers, 10);

if (isNaN(maxPlayers)) {
return res.json([]);
}

const filteredMaxPlayers = boardgames.filter(game =>
game.maxPlayers === maxPlayers
);

res.json(filteredMaxPlayers);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these could be query params under the /boardgames route. Remember to name endpoints after what they return :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants