HttpClientService

The built-in HttpClientService provides an interface for interacting with HTTP servers.

Example

from jetfactory.service import HttpClientService, DatabaseService

from .model import EntryModel

class EntryService(HttpClientService, DatabaseService):
    __model__ = EntryModel

    def __init__(self):
        self.backup_url = 'https://192.168.1.10'

    async def entry_add(self, entry_new):
        entry = await self.create(entry_new)

        self.log.info(f'sending a copy to {self.backup_url}')
        await self.http_post(self.backup_url, entry_new)

        return entry

API

class jetfactory.service.HttpClientService[source]

Service class providing functions for interacting with HTTP servers

Variables:http_client – aiohttp.ClientSession instance
http_get(url: str)[source]

Creates a new HTTP GET request

Parameters:url – URL to send the request to
Returns:aiohttp.ClientResponse
http_post(url: str, payload: dict)[source]

Creates a new HTTP POST request

Parameters:
  • url – URL to send the request to
  • payload – Payload to send
Returns:

aiohttp.ClientResponse

http_request(*args, **kwargs)[source]

Creates a custom HTTP request

Parameters:
  • args – args to pass along to aiohttp.ClientSession.request
  • kwargs – kwargs to pass along to aiohttp.ClientSession.request
Returns:

aiohttp.ClientResponse

classmethod register(pkg, mgr)[source]

Class method used internally by the Jetfactory manager to register a Service

Parameters: