Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Nella: project-express-api #533

wants to merge 4 commits into from

Conversation

nella-x
Copy link

@nella-x nella-x commented Dec 8, 2024

Netlify link

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

https://eventsfordays.netlify.app/

Collaborators

Add any collaborators here.

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.

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"]
}
]
}
});
});
Copy link
Contributor

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

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);
});
Copy link
Contributor

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 ⭐

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