HTTP, HTTPS and APIs: An Interconnection...!

HarshAditya_Gaur
3 min readJan 23, 2023

Our entire web infrastructure relies on different types of protocols that transfer information from one end to another. These protocols are governed by rules and conventions that define how data is exchanged between two or more web entities.

Web Interconnection

Internet communication protocols are standardized by the Internet Engineering Task Force (IETF) and for wired and wireless communication by the Institute of Electrical and Electronics Engineers (IEEE).

For the successful delivery of the information, sender and receiver should follow the same protocols to communicate the data. For that, the most commonly used protocols are HTTP, HTTPS, FTP, SMTP, PPP, RTSP, etc.

HTTP (HyperText Transfer Protocol)

The HTTP (HyperText Transfer Protocol) is a protocol for transferring hypertext over the Internet. It is the fundamental foundation for all data exchange on the Web and is a client-server protocol, which means that the recipient makes requests, which are typically made by the browser. A complete document is rebuilt from the multiple streams, such as text, layout descriptions, images, videos, etc. Due to its ease of use, HTTP became the most widely used protocol for data transfer over the World Wide Web.

Structure of basic HTTP request made by client side.

GET /hello.txt HTTP/1.1
User-Agent: curl/7.63.0 libcurl/7.63.0 OpenSSL/1.1.l zlib/1.2.11
Host: www.google.co.in
Accept-Language: en-in

Information recieved by server side.

HTTP/1.1 200 OK
Date: Wed, 22 Jan 2023 15:19:12 GMT
Server: Apache
Last-Modified: Mon, 22 Jan 2023 15:19:11 GMT
Accept-Ranges: bytes
Content-Length: 12
Vary: Accept-Encoding
Content-Type: text/plain

Hello World!

But it is not secure; hypertext exchanged using HTTP goes as plaintext, which can be intercepted and read by anyone. To overcome this, HTTPS (HyperText Transfer Protocol Secure) came into existence.

HTTPS (HyperText Transfer Protocol Secure)

The letter S in HTTPS stands for the word “SECURE”. HTTPS was developed so that an encrypted session could be established between client and server. It encrypts requests using cryptographic protocols such as TLS and SSL, so any attacker would see a slew of random characters.

Information intercepted by Attacker.

ssfss8746s54s6s66666HUHHLSPF524S65D4S6xkcxX2X4d65D313dDSLMALJA+_UlsLAJSLajsAL351465a43D354D3

Using session keys, HTTP requests and responses are encrypted so that anyone trying to intercept data will only see a randomized sequence of characters rather than the plaintext.

APIs (Application Programming Interface)

APIs are a set of functions and communication protocols that different programmes use to communicate with each other. Any software with a specific purpose is referred to as an application. An interface can be described as a service agreement between two systems. This agreement specifies the requests and responses that the two parties use in order to communicate using an API key. It is a special alphanumeric code used to access or make an API call. There are various types of APIs, namely SOAP APIs, GraphQL APIs, REST APIs, etc.

The main objective of APIs is to hide the internal workings of a system, revealing only the portions that programmers will use and maintaining consistency even if the internal workings change in the future. An API may be developed specifically for a certain set of services that enables communication between groups of systems.

Interconnection:

APIs serve as a connection between two or more apps. They can facilitate interaction over the internet, they are also referred to as web services, and they comply with web standards (HTTP, HTTPS). They can also connect two internal software programs on a local network. The API’s role is to ensure that both app requests and responses are understood. This is the reason protocols are essential. Enabling HTTPS secures interactions between an API and an HTTP client. You can force HTTPS only for encryption, or you can setup a REST API for authentication purposes as well. The JSON file format is retrieved and updated using standard HTTP methods such as GET and POST.

API Request via Python (Sample Code)

import requests

url = "https://example.com/api/v3/db/table/contact_info?limit=5"

headers = {
"cache-control": "no-cache",
"api-key": "sdsjhfuf15e463_eijf"
}

response = requests.request("POST", url, headers=headers)

print(response.text)

API Response

{"resource"
[{"id":1,"ordinal":0,"contact_id":1,"info_type":"home","phone":"1478252125","email":"mary@example.com","address":"14 St.","city":"Brooklyn","state":"NY","zip":"100214","country":"USA"},
{"id":2,"ordinal":0,"contact_id":1,"info_type":"work","phone":"564674156","email":"john@example.com","address":"485 St.","city":"Queens","state":"NY","zip":"100248","country":"USA"},
...]}

Thank You, for reading my blog. For any queries, please feel free to comment.

--

--