gatenet.http_ package

Submodules

gatenet.http_.async_client module

class gatenet.http_.async_client.AsyncHTTPClient(base_url)[source]

Bases: object

Asynchronous HTTP client for making requests using aiohttp.

Supports GET, POST, PUT, PATCH, and DELETE methods via async/await.

Example

>>> import asyncio
>>> from gatenet.http_.async_client import AsyncHTTPClient
>>> async def main():
...     client = AsyncHTTPClient("http://127.0.0.1:8000")
...     resp = await client.get("/status")
...     print(resp)
>>> asyncio.run(main())
{'ok': True, 'status': 200, 'data': {'ok': True}, 'error': None}
async get(path, headers=None)[source]
Return type:

Dict[str, Any]

async post(path, data, headers=None)[source]
Return type:

Dict[str, Any]

gatenet.http_.base module

class gatenet.http_.base.SimpleHTTPRequestHandler(request, client_address, server)[source]

Bases: BaseHTTPRequestHandler

Basic HTTP request handler that responds to GET requests with a plain text message.

Example

>>> from gatenet.http_.base import SimpleHTTPRequestHandler
>>> # Use with Python's HTTPServer for custom GET handling
do_GET()[source]

Handle HTTP GET requests.

Sends a 200 OK response with a plain text message body.

log_message(format, *args)[source]

Override to prevent logging to stderr.

Parameters:
  • format (str) – The format string for the log message.

  • *args (tuple) – Arguments for the format string.

gatenet.http_.client module

class gatenet.http_.client.HTTPClient(base_url)[source]

Bases: object

Lightweight HTTP client for making requests using Python’s built-in urllib.

Supports GET, POST, PUT, PATCH, and DELETE methods via method chaining.

Example

>>> from gatenet.http_.client import HTTPClient
>>> client = HTTPClient("http://127.0.0.1:8000")
>>> response = client.get("/status")
>>> print(response)
{'ok': True, 'status': 200, 'data': {'ok': True}, 'error': None}

gatenet.http_.server module

class gatenet.http_.server.HTTPServerComponent(host='127.0.0.1', port=8000, hooks=None)[source]

Bases: object

Simple HTTP server component for serving JSON responses.

  • Binds to the given host and port.

  • Uses Python’s built-in HTTP server.

  • Runs in a background thread via start().

  • Supports dynamic route registration via the route decorator.

Example

>>> from gatenet.http_.server import HTTPServerComponent
>>> server = HTTPServerComponent(host="127.0.0.1", port=8080)
>>> @server.route("/status", method="GET")
... def status_handler(req):
...     return {"ok": True}
>>> server.start()
# Now visit http://127.0.0.1:8080/status
route(path, method='GET')[source]

Decorator to register a route handler.

Parameters:
  • path (str) – The path to register the handler for.

  • method (str) – The HTTP method (GET, POST, etc.).

start()[source]

Start the server in a background thread.

stop()[source]

Stop the server.

Module contents

class gatenet.http_.AsyncHTTPClient(base_url)[source]

Bases: object

Asynchronous HTTP client for making requests using aiohttp.

Supports GET, POST, PUT, PATCH, and DELETE methods via async/await.

Example

>>> import asyncio
>>> from gatenet.http_.async_client import AsyncHTTPClient
>>> async def main():
...     client = AsyncHTTPClient("http://127.0.0.1:8000")
...     resp = await client.get("/status")
...     print(resp)
>>> asyncio.run(main())
{'ok': True, 'status': 200, 'data': {'ok': True}, 'error': None}
async get(path, headers=None)[source]
Return type:

Dict[str, Any]

async post(path, data, headers=None)[source]
Return type:

Dict[str, Any]

class gatenet.http_.HTTPClient(base_url)[source]

Bases: object

Lightweight HTTP client for making requests using Python’s built-in urllib.

Supports GET, POST, PUT, PATCH, and DELETE methods via method chaining.

Example

>>> from gatenet.http_.client import HTTPClient
>>> client = HTTPClient("http://127.0.0.1:8000")
>>> response = client.get("/status")
>>> print(response)
{'ok': True, 'status': 200, 'data': {'ok': True}, 'error': None}
class gatenet.http_.HTTPServerComponent(host='127.0.0.1', port=8000, hooks=None)[source]

Bases: object

Simple HTTP server component for serving JSON responses.

  • Binds to the given host and port.

  • Uses Python’s built-in HTTP server.

  • Runs in a background thread via start().

  • Supports dynamic route registration via the route decorator.

Example

>>> from gatenet.http_.server import HTTPServerComponent
>>> server = HTTPServerComponent(host="127.0.0.1", port=8080)
>>> @server.route("/status", method="GET")
... def status_handler(req):
...     return {"ok": True}
>>> server.start()
# Now visit http://127.0.0.1:8080/status
route(path, method='GET')[source]

Decorator to register a route handler.

Parameters:
  • path (str) – The path to register the handler for.

  • method (str) – The HTTP method (GET, POST, etc.).

start()[source]

Start the server in a background thread.

stop()[source]

Stop the server.

class gatenet.http_.SimpleHTTPRequestHandler(request, client_address, server)[source]

Bases: BaseHTTPRequestHandler

Basic HTTP request handler that responds to GET requests with a plain text message.

Example

>>> from gatenet.http_.base import SimpleHTTPRequestHandler
>>> # Use with Python's HTTPServer for custom GET handling
do_GET()[source]

Handle HTTP GET requests.

Sends a 200 OK response with a plain text message body.

log_message(format, *args)[source]

Override to prevent logging to stderr.

Parameters:
  • format (str) – The format string for the log message.

  • *args (tuple) – Arguments for the format string.