Difference between GET and POST request in Vanilla JavaScript Last Updated : 13 Jun, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will learn about the GET & POST request method in vanilla Javascript, & will also understand these 2 methods through the examples. GET and POST is two different types of HTTP request methods. HTTP protocol supports many methods to transfer data from the server or perform any operation on the server. The HTTP protocol supports the methods, e.g. GET, POST, PUT, DELETE, PATCH, COPY, HEAD, OPTIONS, etc. Before we dive into the main difference between GET and POST request methods, let's have a look at what does these HTTP methods are. GET request() Method: Data is being requested from a specific resource (through some API URL). Here in the example, a dummy API is used to demonstrate, how GET requests actually work.POST request() Method: Data is sent to be processed to a specific resource (through some API URL). Here in the example, a dummy API is used to demonstrate, how POST request actually works.The GET & POST request methods are used by the fetch() method that is used to request to the server and load the information in the webpages. Example: The example demonstrates the GET request method. JavaScript // Instantiating new XMLHttpRequest() method let xhr = new XMLHttpRequest(); // open() method to pass request // type, url and async true/false xhr.open('GET', 'https://jsonplaceholder.typicode.com/users/2', true); // onload function to get data xhr.onload = function () { if (this.status === 200) { console.log(JSON.parse(this.responseText)); } } // Send function to send data xhr.send() Example: The example demonstrates the POST request method. JavaScript // Instantiating new XMLHttpRequest() let xhr = new XMLHttpRequest(); // open() method to pass request // type, url and async true/false xhr.open('POST', 'http://dummy.restapiexample.com/api/v1/create', true); // Setting content-type xhr.getResponseHeader('Content-type', 'application/json'); // Perform the following when the response is ready xhr.onload = function () { if (this.status === 200) { console.log(this.responseText) } else { console.log("Some error occurred") } } // Send the request as an object obj obj = `{"name":"Selmon Bhoi", "salary":"$10, 000", "age":"55"}`; xhr.send(obj); Difference between GET and POST: S.No.           GET Request                POST Request1. GET retrieves a representation of the specified resource. POST is for writing data, to be processed to the identified resource. 2. It typically has relevant information in the URL of the request. It typically has relevant information in the body of the request. 3. It is limited by the maximum length of the URL supported by the browser and web server. It does not have such limits. 4. It is the default HTTP method. In this, we need to specify the method as POST to send a request with the POST method. 5. You can bookmark GET requests. You cannot bookmark POST requests. 6. It is less secure because data sent is part of the URL It is a little safer because the parameters are not stored in browser history or in web server logs. 7. It is cacheable. It is not cacheable. 8. For eg. GET the page showing a particular question. For eg. Send a POST request by clicking the "Add to cart" button. Comment More infoAdvertise with us T thacker_shahid Follow Improve Article Tags : JavaScript JavaScript-Questions 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