simplelogincmd.rest.client.Client

class Client(base_url: str, verify: bool = True)

Bases: object

A REST API client that ensures JSON responses

Constructor

Parameters:
  • base_url (str) – The API’s base URL. All requests made by this client are based on this URL

  • verify (bool, optional) – Whether to verify certificates, defaults to True

Methods

delete

Make a DELETE request to the given endpoint

get

Make a GET request to the given endpoint

patch

Make a PATCH request to the given endpoint

post

Make a POST request to the given endpoint

put

Make a PUT request to the given endpoint

request

Make a request to the API

delete(endpoint: str = '', **kwargs) tuple[bool, dict | str]

Make a DELETE request to the given endpoint

See request() for param and return info

get(endpoint: str = '', **kwargs) tuple[bool, dict | str]

Make a GET request to the given endpoint

See request() for param and return info

patch(endpoint: str = '', **kwargs) tuple[bool, dict | str]

Make a PATCH request to the given endpoint

See request() for param and return info

post(endpoint: str = '', **kwargs) tuple[bool, dict | str]

Make a POST request to the given endpoint

See request() for param and return info

put(endpoint: str = '', **kwargs) tuple[bool, dict | str]

Make a PUT request to the given endpoint

See request() for param and return info

request(method: str, endpoint: str = '', **kwargs) tuple[bool, dict | str]

Make a request to the API

Parameters:
  • method (str) – The type of HTTP request to make (“GET”, etc)

  • endpoint (str, optional) – The API endpoint to request, the part that comes after the base URL, defaults to “”

  • kwargs (dict) – Keyword arguments passed directly on to the requests.request() function. Here is where you provide JSON, headers, etc.

Returns:

Whether the request succeeded (status code was < 400), and the response as JSON. If the response does not return valid JSON, a dict with key “msg” and value of the response text is returned

Return type:

tuple[bool, dict]