Reflect API client for Python
Make requests to an API built using the Reflect API framework over HTTP or UNIX sockets.
Make a request with Client.call()
. It will always return the response as a tuple of length 2.
- The first value is the HTTP-equivalent response code.
- The second value is the response body
client = Client("<API URL or path to UNIX socket>", "<Optional API key>");
client.call("foo", Method.GET) # (tuple) (200, "bar")
client.call("foo", Method.POST, {
"hello": "world
}) # (tuple) (201, "Created")
# etc..
How to use
Requires Python 3 or newer, and of course a Reflect API endpoint.
-
Install with pip
pip3 install reflect-client
-
Initialize the module
from reflect_client import Client client = Client("<API URL or path to UNIX socket>", "<Optional API key>");
-
Make API request
Use the
call()
method to perform a requestclient.call("foo?bar=baz", Method.GET);
Argument index Type Required Description 0 String Yes Fully qualified pathname and query params of the endpoint to call 1 Method Yes A supported Reflect HTTP method (eg. Method::GET
)2 List No An optional List of key and values to be sent as Content-Type: application/json
to the endpointThe
call()
function will return an array of length 2 wil the following informationIndex Type Description 0 Int HTTP-equivalent response code (eg. 200
or404
)1 String/Array Contains the response body as either a string, or array if the response Content-Type
header isapplication/json