Last active
April 8, 2024 16:48
-
-
Save vmetnev/d7efd5444e51fff5d6590c1ca9343526 to your computer and use it in GitHub Desktop.
POST request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getData() | |
async function getData() { | |
let url = "http://localhost:3001/test" | |
let resp = await fetch(url, { | |
method: "POST", | |
headers: { | |
"content-type": "application/json", | |
}, | |
body: JSON.stringify({ | |
name: "Vlad455", | |
age: 25 | |
}) | |
}) | |
resp = await resp.text() | |
console.log(resp) | |
} | |
// Server Side | |
const express = require("express"); | |
const app = express(); | |
const bodyParser = require("body-parser"); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
app.use(bodyParser.json()); | |
app.post("/test", (req, res) => { | |
res.send(req.body); | |
console.log(req.body); | |
}); | |
app.get("/", (req, res) => { | |
res.sendFile(__dirname + "/index.html"); | |
}); | |
app.listen(3001, () => { | |
console.log("server startered at post 3001"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment