Skip to content

Commit f1dc916

Browse files
authored
Merge pull request #34 from tapascript/day-25
Day 25
2 parents 87b63d6 + f92fb8d commit f1dc916

File tree

12 files changed

+3171
-2
lines changed

12 files changed

+3171
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ I am an independent educator and open-source enthusiast who creates meaningful p
5858
- **`Day 22: Asynchronous JavaScript - Callback`** - [Watch Video](https://youtu.be/EtoHtZ8mdWA) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-22/README.md)
5959
- **`Day 23: JavaScript Promises: Zero to Hero`** - [Watch Video](https://youtu.be/R52MdtIW3rs) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-23/README.md)
6060
- **`Day 24: Master JavaScript async/await & Simplify Promises Like a PRO`** - [Watch Video](https://youtu.be/WQdCffdPPKI) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-24/README.md)
61+
- **`Day 25: JavaScript fetch() Explained Like Never Before`** - [Watch Video](https://www.youtube.com/watch?v=G3oPZSvrO9w) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-25/README.md)

api/blog/db.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"posts": [
3+
{
4+
"title": "What is 40 Days of JavaScript?",
5+
"views": 160,
6+
"id": "a9057951-515e-3da2-9793-af29719d0e33"
7+
},
8+
{
9+
"id": "a9057951-215e-4da2-9793-af29719d0e33",
10+
"title": "How to Split a String?",
11+
"views": 201
12+
},
13+
{
14+
"id": "4b9d7b5c-4a6d-4149-988e-7536ed90a518",
15+
"title": "How to use fetch() API for POST?",
16+
"views": 0
17+
}
18+
],
19+
"comments": [
20+
{
21+
"id": "1",
22+
"text": "Great Post",
23+
"postId": "a9057951-515e-3da2-9793-af29719d0e33"
24+
},
25+
{
26+
"id": "2",
27+
"text": "Learned something new",
28+
"postId": "a9057951-515e-3da2-9793-af29719d0e33"
29+
}
30+
],
31+
"profile": {
32+
"name": "tapaScript"
33+
}
34+
}

api/blog/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "blog",
3+
"version": "1.0.0",
4+
"description": "The Blog API Services used in the tutorials",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node server.js"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/tapascript/40-days-of-javascript.git"
12+
},
13+
"keywords": [
14+
"API"
15+
],
16+
"author": "Tapas Adhikary | tapaScript",
17+
"license": "MIT",
18+
"bugs": {
19+
"url": "https://github.com/tapascript/40-days-of-javascript/issues"
20+
},
21+
"homepage": "https://github.com/tapascript/40-days-of-javascript#readme",
22+
"dependencies": {
23+
"json-server": "0.17.3"
24+
}
25+
}

api/blog/server.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const jsonServer = require("json-server");
2+
const fs = require("fs");
3+
const path = require("path");
4+
5+
const server = jsonServer.create();
6+
const router = jsonServer.router("db.json");
7+
const middlewares = jsonServer.defaults();
8+
9+
server.use(middlewares);
10+
server.use(jsonServer.bodyParser);
11+
12+
server.post("/login", (req, res) => {
13+
console.log("Headers:", req.headers);
14+
console.log("Body:", req.body);
15+
16+
res.json({
17+
message: "LoggedIn successfully!"
18+
});
19+
});
20+
21+
server.use(router);
22+
23+
server.listen(3000, () => {
24+
console.log("✅ JSON Server running at http://localhost:3000");
25+
});

0 commit comments

Comments
 (0)