GET request for config endpoints
Use api_get_config.py to test GET requests.
#!/usr/bin/env python
# Unsupported example code - Not for production use.
import sys
import json
import urllib2
import requests
# default values
#
PROTOCOL = "http://"
PORT = "3000"
if ( len(sys.argv) != 6 ):
print " Usage:", sys.argv[0], "HOST API_ROOT_TOKEN API_TO_CALL HTTP_CODE_TARGET OUTPOST_FILE"
sys.exit(-1)
else:
# get cmdline params
HOST, ROOT_TOKEN, API_TO_CALL, HTTP_CODE_TARGET, OUTPOST_FILE = sys.argv[1:]
# Define the URL in a single variable for JSON load
url = "%s%s:%s%s?token=%s" % (PROTOCOL, HOST, PORT, API_TO_CALL, API_ROOT_TOKEN)
print "Checking " + API_TO_CALL + " on " + HOST + " and writing output to " + OUTPOST_FILE
print " URL is " + url
response = requests.get(url)
print ' SUMMARY (GET): ' + API_TO_CALL, ': HTTP message: ', \
response.reason, ' HTTP return code: ', \
str(response.status_code), ' expected ' + HTTP_CODE_TARGET
target = open(OUTPOST_FILE, 'w')
# To get output data, return a python object and dump it to a string
# that is a JSON representation of that object
data = json.load(urllib2.urlopen(url))
# pretty-print the result
target.write(json.dumps(data, indent=4, sort_keys=True))
target.close()
api_get_config.py makes a GET request, compares expected and actual HTTP return codes in a console output message, and saves the response of the GET request to a file.
Use this script with the following command and arguments:
python api_get_config.py $host $token $endpoint $http_code $output_file- $host
- Hostname or URL for the system running V‑Spark.
- $token
-
Authorization token with the required read or write permissions for the request.
- $endpoint
- Request endpoint, including any path parameters.
- $http_code
- The HTTP code expected to be returned with the response.
- $output_file
- File path for query output.
