CORS, Cross-Origin Resource Sharing: Allowing Cross-Domain Communication

Cross-Origin Resource Sharing (CORS) is an essential mechanism that enables communication between clients and servers, even if they are on different domains. Normally, JavaScript applications running in the browser can only access HTTP resources on the same domain that serves them. However, CORS provides a way to allow connections to other servers. By default, certain resources like images, scripts, and styles can be loaded from different origins. However, requests made using XHR or Fetch to a different domain, subdomain, port, or protocol will fail unless the server implements a CORS policy....

Making HTTP Requests with Axios: A Comprehensive Guide

Axios is a highly popular JavaScript library that allows you to perform HTTP requests in both browser and Node.js platforms. It supports all modern browsers, including IE8 and higher. The library is promise-based, which means you can use async/await syntax to make XHR requests effortlessly. In this blog post, we will cover the basics of Axios and how to use it effectively. Installation To use Axios in a Node.js environment, you can simply install it via npm:...

Same POST API call in different JavaScript libraries

When testing APIs, it’s common to use tools like Insomnia to perform HTTP requests to REST API or GraphQL API services. In this blog, I want to showcase the same API call implemented in different JavaScript libraries. API Call Description Let’s consider an example API call - a POST request to the api.randomservice.com website’s /dog endpoint. The request body includes an object with two properties: name and age, encoded as JSON....

Understanding the ArrayBuffer: What it is and how to use it

In JavaScript, an ArrayBuffer is a data structure that represents a collection of bytes in memory. Similar to a Blob, which represents data available on disk, an ArrayBuffer serves as an opaque representation of bytes available in memory. To create an ArrayBuffer, you need to provide its length in bytes as a parameter in the constructor. Here’s an example: const buffer = new ArrayBuffer(64); Once you have an ArrayBuffer, you can access its length in bytes using the byteLength property, which is read-only....

XMLHttpRequest (XHR)

The introduction of XMLHttpRequest (XHR) in browsers in the mid-2000s was a significant milestone for the Web Platform. In this article, we will explore how XHR works, its capabilities, and compare it with other popular alternatives. Introduction Back in the day, technologies like GMail and Google Maps seemed revolutionary. These applications heavily relied on XHR to deliver dynamic content. XMLHttpRequest was initially invented by Microsoft in the 1990s and became a de-facto standard as all major browsers implemented it between 2002 and 2006....