Consuming Web Services

November 1, 2022

Axios

Client Side

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>

Server Side

To install for server-side:

npm install axios

Require with:

const axios = require('axios');

Get Request

async function getCall() {
    const result = await axios.get('http://url-to-get.com');
    return result.data;
}

Post Request

async function postCall() {
    const result = await axios.post('http://url-to-get.com', {
        product_id: 1,
        quantity: 1
    });
    return result.data;
}