-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nella: project-express-api #533
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work Nella, and nice to see that you created a frontend as well 🥳
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"] | ||
} | ||
] | ||
} | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next week you might want to look into the package Express List Endpoints
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); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and RESTful making use of query params to be able to chain the filters like this ⭐
Netlify link
https://project-express-api-gep6.onrender.com/
https://eventsfordays.netlify.app/
Collaborators
Add any collaborators here.