How to make POST call to an API using Axios.js in JavaScript ? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Axios is a promise-based HTTP client designed for Node.js and browsers. With Axios, we can easily send asynchronous HTTP requests to REST APIs and perform create, read, update and delete operations. It is an open-source collaboration project hosted on GitHub. It can be imported in plain Javascript or with any library accordingly. The following script-src will include axios.js in the head section of your HTML code <script src="https://unpkg.com/axios/dist/axios.min.js"></script> When we send a request to the API using axios, it returns a response. The response object consists of: data: the data returned from the server.status: the HTTP code returned from the server.statusText: the HTTP status returned by the server.headers: headers obtained from the server.config: the original request configuration.request: the request object. For the purpose of demonstration, we will be hosting an API on the localhost: http://127.0.0.1:5000 Python Script: You will be requiring the following packages to run the API: flask, requests, jsonify, and flask_cors. The code for the Python API is as follows: Example: Python3 from flask import Flask, jsonify, request from flask_cors import CORS app = Flask(__name__) CORS(app) @app.route('/test', methods =['POST']) def test(): return jsonify({"Result": "Welcome to GeeksForGeeks, " +request.json['name']}) if __name__ == '__main__': app.run(debug = True) Note: You can host this API by simply running the above python code.JS Script: Include axios.js and the corresponding JS file in the HTML file. In the JS file, write the following code which makes a POST request using axios to the API. A POST request to the API requires the following variables: path: The path to the API method.queryObj: Query Object which contains the header data for the POST call. The query object is in the form of a Javascript object. For example: {name:'GeeksForGeeks', type:'Website'} Example: javascript function makePostRequest(path, queryObj) { axios.post(path, queryObj).then( (response) => { let result = response.data; console.log(result); }, (error) => { console.log(error); } ); } queryObj = { name: 'Chitrank' }; makePostRequest('http://127.0.0.1:5000/test', queryObj); Output: It will call the API with a POST request carrying the mentioned header data. The response obtained will be obtained on the console window. Comment More infoAdvertise with us C chitrankmishra Follow Improve Article Tags : JavaScript JavaScript-Misc Similar Reads JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read Introduction to JavaScript JavaScript is a versatile, dynamically typed programming language used for interactive web applications, supporting both client-side and server-side development, and integrating seamlessly with HTML, CSS, and a rich standard library.JavaScript is a single-threaded language that executes one task at 7 min read JSON Web Token (JWT) A JSON Web Token (JWT) is a standard used to securely transmit information between a client (like a frontend application) and a server (the backend). It is commonly used to verify users' identities, authenticate them, and ensure safe communication between the two. JWTs are mainly used in web apps an 7 min read Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie 15+ min read JavaScript Coding Questions and Answers JavaScript is the most commonly used interpreted, and scripted Programming language. It is used to make web pages, mobile applications, web servers, and other platforms. Developed in 1995 by Brendan Eich. Developers should have a solid command over this because many job roles need proficiency in Jav 15+ min read Top 95+ Javascript Projects For 2025 JavaScript is a lightweight, cross-platform programming language that powers dynamic and interactive web content. From real-time updates to interactive maps and animations, JavaScript brings web pages to life.Here, we provided 95+ JavaScript projects with source code and ideas to provide hands-on ex 4 min read Functions in JavaScript Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code. It can take inputs, perform actions, and return outputs.JavaScriptfunction sum(x, y) { return x + y; } console.log(sum(6, 9)); // output: 15Function Syntax 5 min read JavaScript Exercises, Practice Questions and Solutions JavaScript Exercise covers interactive quizzes, tracks progress, and enhances coding skills with our engaging portal. Ideal for beginners and experienced developers, Level up your JavaScript proficiency at your own pace. Start coding now! A step-by-step JavaScript practice guide for beginner to adva 3 min read HTML DOM (Document Object Model) The HTML DOM (Document Object Model) is a programming interface that represents the structure of a web page in a way that programming languages like JavaScript can understand and manipulate. Think of it as a tree of objects where each part of your HTML document (elements, attributes, text) is repres 6 min read Like