Skip to content

Commit 8ab4e9a

Browse files
committed
Week 2 Lessons 3.4.2: Add a New Album
Added the following album by using request.body and then using .push method to append the new album to the albums data and finally sending it as a response: { "albumId": "13", "artistName": "Beyoncé", "collectionName": "B'Day (Deluxe Edition)", "artworkUrl100": "http://is5.mzstatic.com/image/thumb/Music/v4/6c/fc/6a/6cfc6a13-0633-f96b-9d72-cf56774beb4b/source/100x100bb.jpg", "releaseDate": "2007-05-29T07:00:00Z", "primaryGenreName": "Pop", "url": "https://www.youtube.com/embed/RQ9BWndKEgs?rel=0&controls=0&showinfo=0" } Tested by sending: localhost:35981/albums to check the new album is added to all albums list.
1 parent ab78358 commit 8ab4e9a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ app.get("/albums/:albumId", (req,res) => {
7373
res.send({ albumMatchingID })
7474
})
7575

76+
app.post("/albums", (req, res) => {
77+
const newAlbum = req.body;
78+
albumsData.push(newAlbum);
79+
res.status(201).send({ newAlbum });
80+
});
81+
7682
app.listen(35981, function () {
7783
console.log("Server is listening on port 35981. Ready to accept requests!");
7884
});

0 commit comments

Comments
 (0)