HTTP vs HTTPS and APIs
Published: 2023-01-22 22:16:13


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8n243q0djjj3wlohd2k.png)

## What Is HTTP?
HTTP stands for **HyperText Transfer Protocol**. It is invented by Tim Berner. It’s most commonly used to transfer data from a web server to a browser to allow users to view web pages.

##HTTP request
HTTP works by opening a connection. For example, when you click on a web page link, your **web browser sends an HTTP request** to a web server. The web server then **responds to the request with a data packet** that the browser shows you as a website. Most information that is sent over the Internet, including website content and API calls, uses the HTTP protocol. There are two main kinds of HTTP message **requests** and **responses**.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/umot1xdz8f9tozxpbbq4.jpg)

##HTTP Security
HTTP is an **application layer protocol**. HTTP transfers plain text over the connection which can be read by someone who has access to your connection. For example, if you are exchanging data over shared wifi one can sniff your data using sniffers. Google Chrome and other browsers flag all non-HTTPS websites as **Not secure**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rj0r1odsik4nh7yfexzf.jpg)


##What Is HTTPS?
HTTPS stands for **Hypertext Transfer Protocol Secure** and is an **extension** of the **Hypertext Transfer Protocol (HTTP)**. An HTTPS protocol uses either **Secure Socket Layer (SSL) or Transport Layer Security (TLS)** protocol to make the HTTP request secure.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtoyw2up6t2gwnxkf3pl.jpg)

##HTTPS Security
It uses **cryptography for secure communication** over a computer network and is widely used on the Internet. In modern web browsers such as Chrome, websites that do not use HTTPS are marked differently than those that are. HTTPS uses an **asymmetric public key** infrastructure for securing a communication link.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urpkmfebvd3jpw8n08wo.jpg)

##HTTPS Encryption
There are two different kinds of keys used for encryption-

**Private Key:** This key is controlled by the owner of a website and it’s kept, as the reader may have speculated, private. This key lives on a web server and is used to decrypt information encrypted by the public key.

**Public Key:** It is public and is accessible to all the users who communicate with the server. The private key is used for the decryption of the data that has been encrypted by the public key.

##Difference Between HTTP and HTTPS
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cuutytb736iqioy9aj2g.jpg)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kbb3xxwujnj4zcv8uh9u.jpg)

##What is API?

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tj0trpstsvh3q9hrbh6.jpg)
The API stands for an **Application Programming Interface**. It serves as a data transmitter between two **different pieces of software**. The working principle of an API is commonly expressed through the **request-response communication between** a client and a server. The client is any front-end application that a user interacts with. The server is in charge of backend logic and database operations. In this scenario, an API works as a middle layer between the client and the server, making it possible to send data requests and responses.

##API gateway

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nelb3691nx2zjqrk239s.jpg)
An API Gateway is an **API management tool** for enterprise clients that use a broad range of back-end services. API gateways typically handle common tasks like **user authentication**, **statistics**, and **rate management** that are applicable across all API calls. It intercepts all **incoming requests** and sends them through the API management system, which handles a variety of necessary functions.

##Migrating APIs to HTTPS

All APIs should use and require HTTPS to help guarantee confidentiality, authenticity, and integrity.

HTTPS provides a stronger guarantee that a client is communicating with the real API and receiving back authentic content. It also enhances privacy for applications and users using the API. For APIs that support cross-origin request sharing (CORS) or JSONP requests, it also ensures the requests are not blocked as mixed content.

All new APIs should use and require HTTPS. Rather than issue a redirect when visited over HTTP (redirects within APIs are problematic, as outlined below), the API should likely return an error message (such as the HTTP status code 403 Forbidden).