Skip to content

Day 25 #34

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

Merged
merged 4 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ I am an independent educator and open-source enthusiast who creates meaningful p
- **`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)
- **`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)
- **`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)
- **`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)
34 changes: 34 additions & 0 deletions api/blog/db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"posts": [
{
"title": "What is 40 Days of JavaScript?",
"views": 160,
"id": "a9057951-515e-3da2-9793-af29719d0e33"
},
{
"id": "a9057951-215e-4da2-9793-af29719d0e33",
"title": "How to Split a String?",
"views": 201
},
{
"id": "4b9d7b5c-4a6d-4149-988e-7536ed90a518",
"title": "How to use fetch() API for POST?",
"views": 0
}
],
"comments": [
{
"id": "1",
"text": "Great Post",
"postId": "a9057951-515e-3da2-9793-af29719d0e33"
},
{
"id": "2",
"text": "Learned something new",
"postId": "a9057951-515e-3da2-9793-af29719d0e33"
}
],
"profile": {
"name": "tapaScript"
}
}
25 changes: 25 additions & 0 deletions api/blog/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "blog",
"version": "1.0.0",
"description": "The Blog API Services used in the tutorials",
"main": "index.js",
"scripts": {
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tapascript/40-days-of-javascript.git"
},
"keywords": [
"API"
],
"author": "Tapas Adhikary | tapaScript",
"license": "MIT",
"bugs": {
"url": "https://github.com/tapascript/40-days-of-javascript/issues"
},
"homepage": "https://github.com/tapascript/40-days-of-javascript#readme",
"dependencies": {
"json-server": "0.17.3"
}
}
25 changes: 25 additions & 0 deletions api/blog/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const jsonServer = require("json-server");
const fs = require("fs");
const path = require("path");

const server = jsonServer.create();
const router = jsonServer.router("db.json");
const middlewares = jsonServer.defaults();

server.use(middlewares);
server.use(jsonServer.bodyParser);

server.post("/login", (req, res) => {
console.log("Headers:", req.headers);
console.log("Body:", req.body);

res.json({
message: "LoggedIn successfully!"
});
});

server.use(router);

server.listen(3000, () => {
console.log("✅ JSON Server running at http://localhost:3000");
});
Loading