In javascript if we want to integrate rest api we can use below code is for get api.
async function getData() { const url = "https://apirequest.in/users/"; try { const response = await fetch(url); if (!response.ok) { throw new Error(`Response status: ${response.status}`); } const json = await response.json(); console.log(json); } catch (error) { console.error(error.message); } }
In javascript if we want to integrate rest api we can use below code is for POST api.
async function postData() { const url = "https://apirequest.in/users/"; try { let data = { "email":"sampleemail@gmail.com", "password":"samplepassword" } const response = await fetch(url,{"method":"POST",body:JSON.stringify(data)}); if (!response.ok) { throw new Error(`Response status: ${response.status}`); } const json = await response.json(); console.log(json); } catch (error) { console.error(error.message); } }