-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 775 Bytes
/
index.js
File metadata and controls
36 lines (28 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import express from "express";
import cors from "cors";
const app = express();
const PORT = 3000;
app.use(cors());
app.use(express.json());
app.get("/", (req, res) => {
res.send("Playing Card API is running 🚀");
});
let cards = [
{ id: 1, suit: "hearts", value: "ace", collection: "vintage" }
];
app.get("/api/cards", (req, res) => {
res.json(cards);
});
app.post("/api/cards", (req, res) => {
const newCard = { id: Date.now(), ...req.body };
cards.push(newCard);
res.status(201).json(newCard);
});
app.delete("/api/cards/:id", (req, res) => {
const id = parseInt(req.params.id);
cards = cards.filter(card => card.id !== id);
res.json({ message: "Card deleted" });
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});