Skip to content

hhru/balancing-http-client

Repository files navigation

Balancing http client around aiohttp

usage example:

import asyncio
from http_client import HttpClientFactory, AIOHttpClientWrapper
from http_client.balancing import RequestBalancerBuilder, Server, Upstream

async def runner():
    servers = [Server('127.0.0.1:9400', 10), Server('127.0.0.1:9401', 20)]
    request_balancer_builder = RequestBalancerBuilder({'backend1': Upstream('backend1', {}, servers)})
    http_client_factory = HttpClientFactory('app-name', AIOHttpClientWrapper(), request_balancer_builder)

    http_client = http_client_factory.get_http_client()

    result = await http_client.get_url('backend1', '/some_page')

    if not result.failed:
        print(result.data)


asyncio.run(runner())