What is HTTP (in a nutshell) In a nutshell, HTTP is just a way for computers (i.e. your computer and a server) to talk to each other. You can think of it as the ' of computers. WhatsApp' In nerd terms, HTTP stands for HyperText Transfer Protocol. HTTP follows what we call the , where a client (for example, your browser) opens a connection between your computer and a server to make a request, then waits until it receives a response. client-server model Most of us aren't aware of this as it's abstracted away from us by our browsers so that we can just click and drag anywhere on a website for a smooth User Experience. Maybe it's no use for us Average Joes on what the heck is HTTP but not for people who code, especially those who make apps that are connected to the internet. Knowing HTTP is part of a developer toolbox, though you don't really need to always think about it. CRUD operations Some smart people aren't really good at naming things, eh? But anyway, CRUD stands for: . Create, Read, Update, Delete So what's the connection? actually is used by the client (i.e. your browser) to tell the server what is it's intention. It's like "Hey server, I need this to happen, can you do it for me?", then it waits for the response of the server. CRUD For example, you entered YouTube.com into your browser. Your browser then sends a request to YouTube's server to retrieve some file. Basically, it's asking for files like , etc. so that it can render the YouTube website to your screen. If the YouTube server is fine with this request, it will accept the request, and send to your browser the requested files. GET html, css, js, image, video So that's the or part in , "gimmie something!" R Read CRUD But what if you want to comment on a video? This is when your browser sends a (or sometimes ) request to YouTube's server. It's like saying "Hey YouTube, I want this comment for this video to be saved to your database, can you save it for me?". And again, your browser waits for the response, and if youtube is fine with this request, it will accept the comment, save it to its database, and responds to the browser confirming the request, "all done!" POST PUT So this is the or part of , "save this!" C Create CRUD And for and requests, you know how it goes. UPDATE DELETE Requests library OK, enough for the definitions, let's get straight into it. In Python, instead of letting the browser do the requests for us, we can directly communicate to the server ourselves via the Requests library. this is the tagline of the Requests library and it clearly speaks what it does. "Requests: HTTP for humans" , To start working with it, let's do a simple pip install. Most folks pip installs this way: Mac/Linux $ pip3 install requests folks do pip this way: Windows C:\ > Users pip install requests Making Requests Let's get through each of the operations with requests. CRUD For these examples, we will be using ' ' as a mock API. Here's the base URL: JSON Placeholder https://jsonplaceholder.typicode.com OK, so first, let's import requests and start getting some fake posts data: requests URL = res = requests.get(URL + ) print(res.json()) import 'https://jsonplaceholder.typicode.com' '/posts' So what's going on here? First, we saved our base URL on a variable so that we don't have to copy-paste it repeatedly, then we sent a simple get request to the server in just a single line. The is called an which basically tells the server where to get the data from its resources. JsonPlaceholder '/posts' End point Then finally, we print the JSON data. If you're unsure what's , you can check out Mozilla's guide, but basically, it looks like Python dictionaries and it is what's being exchanged between clients and servers. In a nutshell, this is the ' they send to each other. JSON message' By running the above code, we will get something like this: [ { : , : , : , : }, { : , : , : , : }, { : , : , : , : }, ... "userId" 1 "id" 1 "title" "sunt aut facere repellat provident occaecati excepturi optio reprehenderit" "body" "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" "userId" 1 "id" 2 "title" "qui est esse" "body" "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla" "userId" 1 "id" 3 "title" "ea molestias quasi exercitationem repellat qui ipsa sit aut" "body" "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut" And that's basically the data that represents the posts on a website. When your writing programs let's say for front-end, you'll expect to get these data from the server and you build the look and feel of the app from these data. Here's how you do with request: POST, PUT, and DELETE r = requests.post(URL + , data={ : , : , : }) r = requests.put(URL + , data={ : , : , : }) r = requests. (URL + ) '/posts' 'title' 'How HTTP work?' 'body' 'Lorem ipsum...' 'userId' '1' '/posts/1' 'id' 1 'title' 'How HTTP work?' 'body' 'HTTP is used by...' delete '/posts/1' Downloading files with Python So what are some other things we can use requests for? A LOT! For everything that relates to the internet, requests can be useful in one way or the other. For example, we can download files like these fun little comics: import requests = res = requests. ( ) ( , ) : . (res.content) print( ) # fetch the file URL 'https://imgs.xkcd.com/comics/python.png' get URL # save the file with open 'antigravity.png' 'wb' as file file write 'Downloaded successfully!' Make sure to check out the comics 😝 Other Uses of Requests: Web Scraping API integration Me on social media (follow me!): Twitter 🐦 Instagram 📷 Also published on Medium's menardmaranan-codes