Skip to content

REST APIs#

REST APIs are a standard that use HTTP requests sent to specific URL endpoints to allow programs to interact with a server. The most common types of request are GET, POST, and DELETE.

The requests module#

A 3rd party library for python, requests is often used to manage network requests due to its ease of use. requests has built in functions for assembling these requests in the backend, so sending an unauthorized GET request is as simple as requests.get(url). There are many other functions in this module that can be discovered in the documentation.

Headers#

Headers are additional data sent as part of an HTTP request. Many things are encoded in these headers to identify what kind of network traffic something is (try looking at the headers attribute of the response returned from a requests call), and often they are used to transmit authentication for protected data. In python, we assemble these via a dictionary, as so:

headers = {  
    "username": "Zach",  
    "password": "Squeer",  
}

Note that there are built in methods in the requests module for handling this assembly

Params#

Parameters (or params) are additional data needed to complete the API request, and can be manually encoded into the url used for the api request. They can be identified by a question mark preceding them.

https://www.youtube.com/watch?v=dQw4w9WgXcQ
                              ^^^^^^^^^^^^^
                              This is a parameter                 

In python we would, again, transmit this by packaging it into a dictionary and sending it via the params keyword in the function we use for the request.

myparams = {
    "v": "dQw4w9WgXcQ"
}

response = requests.get(url, auth=(username, password), params=myparams)

Google Authentication#

SQL#