Created
February 26, 2021 00:31
-
-
Save axolx/2b9718c9b56b59ba1a2238b43ce3f75f to your computer and use it in GitHub Desktop.
Sample Python code for making requests to the eTRM API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Sample Python code for making requests to the eTRM API | |
""" | |
import http.client | |
import json | |
TOKEN = "SETME" | |
API_ENDPOINT = "/api/v1/measures/" | |
# Make HTTP request | |
print(f"Request: {API_ENDPOINT}") | |
conn = http.client.HTTPSConnection("www.caetrm.com") | |
headers = {"Authorization": f"Token {TOKEN}"} | |
conn.request("GET", API_ENDPOINT, headers=headers) | |
# Process the HTTP response | |
response = conn.getresponse() | |
response_body = json.loads(response.read().decode()) | |
# Print output | |
print(f"Response status code: {response.status}") | |
print(json.dumps(response_body, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this achievable with JavaScript and to show permutations based on user input?