-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.js
More file actions
32 lines (21 loc) · 666 Bytes
/
Copy pathtask2.js
File metadata and controls
32 lines (21 loc) · 666 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
import fs from 'fs'
import fetch from 'node-fetch'
// Read the JSON file
const data= fs.readFileSync("./payload/data2.json", "utf-8");
const url= 'https://reqres.in/api/users'
// Replace the variables with desired values
try{
const name = 'Ram';
const job = 'Developer';
const requestBody = JSON.stringify(JSON.parse(data.replace("${name}", name).replace("${job}", job)));
// // send the POST request
const response = await fetch(url,{
method:"POST",
body:requestBody,
headers:{"Content-Type":"application/json"}
})
const jsonData = await response.json();
console.log(jsonData)
}catch(err){
console.log("Error Occured")
}