Skip to main content

Command Palette

Search for a command to run...

Understanding APIs And Request Parameters

Updated
Understanding APIs And Request Parameters

what is an API

API stands for Application Programming Interface. In the context of web apps, it serves as a bridge between the frontend and the backend of an application. For example, let's say you want to build an application that provides live updates for different sports. Streaming live data directly can be expensive. A more cost-effective option is to obtain data from a service that can provide updates for a specific sport.

Instead of managing live data streaming yourself, you can make use of an API provided by a sports data service. This API allows your application to send requests for live updates, specifying the particular sport or events you're interested in. The API then processes these requests, interacts with its database or data sources, and sends back the relevant information in a structured format.

How do APIs work?

Consider a web API, for example. In this scenario, there is a client and a server engaged in a cycle of sending requests and receiving responses, typically over the internet. This interaction is referred to as an API call. There are two key components in these calls: the request URL and the request method.

Working with APIs

When dealing with APIs, there are "request options" which generally refer to the various configuration settings or parameters that can be included in an API request to customize the behavior of that request.

Common Headers

HTTP headers are metadata elements in an HTTP request or response that provide additional information about the message.

Content-Type: Specifies the media type of the resource being sent or requested. In general, data will be text, image, audio, video, or application. For example, text/html indicates that the data is HTML text, while image/png indicates that the data is a PNG image or application/json indicates that the data is a JSON document.

Cookie

The Cookie header is like a container for all notes which are given to the browser

  1. Name: This is like a label on the note, telling the website what the information is for. For example, a note might be labeled "username" to store your login name.

  2. Value: This is the actual information you want the website to remember. In the username example, the value might be your specific username.

You can leave multiple notes (cookies) for the same website. Each note is separated by a semicolon (;) just like separating notes on a sticky note pad. This way, the website can keep track of all the different things you want it to remember.

Cookie:  user=john; csrftoken=Uwef409rjiwe

Cors

CORS, or Cross-Origin Resource Sharing, is an HTTP mechanism that enables web browsers to decide if a resource from one domain can be accessed by a script on another domain. This is crucial for security, as it helps prevent malicious scripts from stealing data from other websites.

Common Request Options

Request options refer to various settings and configurations that can be specified when making an API request.

HTTP Methods :

They play a crucial role in defining the operations that can be performed on resources exposed by the API. They serve as the verbs that describe the actions to be taken on the identified resources.

  • GET: Retrieve data from the server.

  • POST: Send data to the server to create a new resource.

  • PUT: Update an existing resource on the server.

  • DELETE: Remove a resource from the server.

  • PATCH: Update specific parts of an existing resource.

Query Parameters:

They are key-value pairs appended to the URL after a question mark (?). Each pair consists of a key, which identifies the instruction, and a value, which specifies the details of that instruction. Ampersands (&) separate multiple key-value pairs.

Here's a breakdown of a URL with query parameters:

For example, consider this URL:

https://example.com/products?category=electronics&sort=price_asc

In essence, query parameters offer a concise way to dynamically alter a web server's response based on specific instructions.

Request Body :

A request body is data sent from a client (like your browser) to a server in an HTTP request. It's like the contents of a package you send, containing the important information for the server.

Authentication :

It is the process of verifying a user or application's identity before granting access to resources. It's like a handshake to confirm someone is who they say they are. There are different ways to achieve this:

Backend

Part 1 of 1