November 1, 2022
We will use axios for both server-side and client-side interactions with web services.
To use client-side, include the axios library:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
To install for server-side:
npm install axios
Require with:
const axios = require('axios');
async function getCall() {
const result = await axios.get('http://url-to-get.com');
return result.data;
}
async function postCall() {
const result = await axios.post('http://url-to-get.com', {
product_id: 1,
quantity: 1
});
return result.data;
}