core_lib.client.client_base.ClientBase [source]
Client Base class provides functions by which we can interface with the HTTP APIs.
Initializing
def __init__(self, base_url):
Arguments
base_url: Base URL of the API to be used.
Example
from core_lib.client.client_base import ClientBase
client = ClientBase('https://example.com/')
Functions
_get()
core_lib.client.client_base.ClientBase._get() [source]
Will make a GET request to the path provided. Used to fetch data.
def _get(self, path: str, *args, **kwargs) -> Response:
Arguments
path(str): The API path to make the request.- *args, **kwargs: The args and kwargs of the function, if the API accepts some parameters, will be passed to the
requests.getfunction.
Returns
(Response): The response object is returned by the API.
Example
from core_lib.client.client_base import ClientBase
client = ClientBase('https://example.com/')
user_data = client._get('user/1')
print(user_data) # will print the response returned by the API.
_put()
core_lib.client.client_base.ClientBase._put() [source]
Will make a PUT request to the path provided. Used to create or replace data.
def _put(self, path: str, *args, **kwargs) -> Response:
Arguments
path(str): The API path to make the request.- *args, **kwargs: The args and kwargs of the function, if the API accepts some parameters, will be passed to the
requests.putfunction.
Returns
(Response): The response object is returned by the API.
Example
from core_lib.client.client_base import ClientBase
client = ClientBase('https://example.com/')
data = client._put('update/user', {'id': 1 , 'username': 'Jon Doe'})
print(data) # will print the response returned by the API.
_post()
core_lib.client.client_base.ClientBase._post() [source]
Will make a POST request to the path provided. Used to send data to the backend.
def _post(self, path: str, *args, **kwargs) -> Response:
Arguments
path(str): The API path to make the request.- *args, **kwargs: The args and kwargs of the function, if the API accepts some parameters, will be passed to the
requests.postfunction.
Returns
(Response): The response object is returned by the API.
Example
from core_lib.client.client_base import ClientBase
client = ClientBase('https://example.com/')
data = client._post('create/user', {'username': 'Jon Doe', 'password': 'password',...})
print(data) # will print the response returned by the API.
_delete()
core_lib.client.client_base.ClientBase._delete() [source]
Will make a DELETE request to the path provided. Used to delete data.
def _delete(self, path: str, *args, **kwargs) -> Response:
Arguments
path(str): The API path to make the request.- *args, **kwargs: The args and kwargs of the function, if the API accepts some parameters, will be passed to the
requests.deletefunction.
Returns
(Response): The response object is returned by the API.
Example
from core_lib.client.client_base import ClientBase
client = ClientBase('https://example.com/')
data = client._delete('user/1')
print(data) # will print the response returned by the API.