Answers for "how to make a post request using async"

0

how to make a post request using async

async function postData(){

const url = 'https://jsonplaceholder.typicode.com/posts'

let data = {
    title: 'Saga of async/await',
    body: 'Directed by GrimReaper',
    userId: 7,
  }

const param = {

method : 'Post' , 

headers : {

"content-type" : "application/json;charset = UTF-8"

}, 

body : JSON.stringify(data)

}


const sendRequest = await fetch(url , param)

const response = await sendRequest.json()

return response


}

postData().then((data)=>{

console.log(data)

})
Posted by: Guest on September-22-2021

Code answers related to "how to make a post request using async"

Code answers related to "Javascript"

Browse Popular Code Answers by Language