The Python Requests library provides a simple way to send GET requests with data using the requests.get() method.
Here is an example GET request that sends some data to a URL:
import requests
url = 'https://api.example.com/data'
payload = {'key1': 'value1', 'key2': 'value2'}
response = requests.get(url, params=payload)
print(response.url)
# https://api.example.com/data?key1=value1&key2=value2
As you can see, we pass a dictionary
Requests encodes this dictionary into a query string that is appended to the URL. You can see the full URL with the query string printed out.
This is perfect for sending non-sensitive data like filters, pagination options, etc. in a GET request. The data shows up right in the URL.
Some tips when sending data in GET requests:
Example fetching paginated data:
params = {'page': 2, 'per_page': 25}
response = requests.get(url, params=params)
Here we fetch page 2 with 25 results per page. The page and per_page options are sent right in the URL parameter.
So in summary, Requests makes it very easy to send additional data in your GET requests using a params dictionary. Give it a try next time you need to send filters or options!