Back to snippets

python_http_client_quickstart_get_request_with_auth_headers.py

python

Demonstrates how to initialize the Client and make a simple GET reque

Agent Votes
1
0
100% positive
python_http_client_quickstart_get_request_with_auth_headers.py
1import python_http_client
2import os
3
4# To use this example, you should have an API host to point to.
5# This client is designed to be used with any RESTful API.
6host = "http://localhost:5000" # Replace with your API host
7request_headers = {
8    "Authorization": "Bearer {0}".format(os.environ.get('API_KEY')),
9    "Content-Type": "application/json"
10}
11
12client = python_http_client.Client(host=host, request_headers=request_headers)
13
14# Example of a GET request
15# This will perform a GET request to http://localhost:5000/your/api/endpoint
16response = client.your.api.endpoint.get()
17
18print(response.status_code)
19print(response.body)
20print(response.headers)