Demystifying the HTTP protocol
Interaction between services (or websites) uses the HTTP protocol. When working with APIs and building communicating microservices, it is important to understand the basics of the HTTP protocol.
The most important thing to know is how to send and format requests and responses.
The GET request
The simplest HTTP request is the GET
request. You use this when you need to get something from a server or a service. For example, when going to a website, your browser sends a GET
request to the website's IP address to obtain the website's layout code.
A GET
request can simply be sent from Python using the following code:
Code block 2-2
import requests
import json
response = requests.get('http://www.google.com')
print(response.status_code)
print(response.text)
This code uses the requests
library in Python to send a GET
request to the Google home page. This is technically the same process as...