Open
Conversation
HIPPIEKICK
approved these changes
Dec 10, 2024
Contributor
HIPPIEKICK
left a comment
There was a problem hiding this comment.
Excellent work Nella, and nice to see that you created a frontend as well 🥳
Comment on lines
41
to
65
| app.get("/", (req, res) => { | ||
| res.send("Hello Technigo!"); | ||
| res.json({ | ||
| message: "Welcome to the Events API! Here are the available endpoints:", | ||
| description: { | ||
| "/events": "Get all events (optionally filter by city or category)", | ||
| "/events/:id": "Get a specific event by ID", | ||
| "endpoints": [ | ||
| { | ||
| path: "/events", | ||
| methods: ["GET"], | ||
| middlewares: ["anonymous"], | ||
| queryParameters: { | ||
| city: "Filter events by city name (case insensitive)", | ||
| category: "Filter events by category (e.g., 'music', 'art')" | ||
| } | ||
| }, | ||
| { | ||
| path: "/events/:id", | ||
| methods: ["GET"], | ||
| middlewares: ["anonymous"] | ||
| } | ||
| ] | ||
| } | ||
| }); | ||
| }); |
Contributor
There was a problem hiding this comment.
Next week you might want to look into the package Express List Endpoints
Comment on lines
+11
to
+27
| app.get("/events", (req, res) => { | ||
| let filteredEvents = eventsData; | ||
|
|
||
| const { city, category } = req.query; | ||
|
|
||
| if (city) { | ||
| filteredEvents = filteredEvents.filter(event => event.city.toLowerCase().includes(city.toLowerCase())); | ||
| } | ||
|
|
||
| if (category) { | ||
| filteredEvents = filteredEvents.filter(event => | ||
| event.category.some(cat => cat.toLowerCase().includes(category.toLowerCase())) | ||
| ); | ||
| } | ||
|
|
||
| res.json(filteredEvents); | ||
| }); |
Contributor
There was a problem hiding this comment.
Nice and RESTful making use of query params to be able to chain the filters like this ⭐
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Netlify link
https://project-express-api-gep6.onrender.com/
https://eventsfordays.netlify.app/
Collaborators
Add any collaborators here.