Created
July 12, 2016 14:27
-
-
Save ableasdale/b94ea4ce4c47a30796ea32660b89e8ee to your computer and use it in GitHub Desktop.
Using the Python httplib2 to connect to MarkLogic's ReST API
This file contains hidden or 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
import httplib2 | |
h = httplib2.Http() | |
h.add_credentials('username', 'password') | |
TIMESTAMP_URI = "http://localhost:8001/admin/v1/timestamp" | |
REST_URI = "http://localhost:8002/LATEST/rest-apis" | |
BODY = body = "" | |
ACCEPT_JSON = headers = {'Accept': 'application/json'} | |
ACCEPT_XML = headers = {'Accept': 'application/xml'} | |
def print_http_response(uri, verb, req_body, header): | |
response_header, response_body = h.request(uri, verb, req_body, header) | |
print(response_header, "\n", response_body, "\n", "----") | |
print_http_response(TIMESTAMP_URI, "GET", BODY, ACCEPT_XML) | |
print_http_response(REST_URI, "GET", BODY, ACCEPT_JSON) | |
print_http_response(REST_URI, "GET", BODY, ACCEPT_XML) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment