gfwapiclient.http.endpoints.abc

Global Fishing Watch (GFW) API Python Client - Abstract Base HTTP EndPoint.

Module Contents

Classes

AbstractBaseEndPoint

Abstract base class for an API resource endpoint.

Data

API

gfwapiclient.http.endpoints.abc.__all__ = ['AbstractBaseEndPoint']
class gfwapiclient.http.endpoints.abc.AbstractBaseEndPoint(*, method: http.HTTPMethod, path: str, request_params: Optional[gfwapiclient.http.models.request._RequestParamsT], request_body: Optional[gfwapiclient.http.models.request._RequestBodyT], result_item_class: Type[gfwapiclient.http.models.response._ResultItemT], result_class: Type[gfwapiclient.http.models.response._ResultT], http_client: gfwapiclient.http.client.HTTPClient)

Bases: abc.ABC, typing.Generic[gfwapiclient.http.models.request._RequestParamsT, gfwapiclient.http.models.request._RequestBodyT, gfwapiclient.http.models.response._ResultItemT, gfwapiclient.http.models.response._ResultT]

Abstract base class for an API resource endpoint.

Provides a structured way to define API endpoints and their result format.

This class handles:
  • Preparing request method, URL, headers, query parameters, and JSON body.

  • Building the HTTP request.

Initialization

Initialize an API endpoint.

Args:
method (http.HTTPMethod):

The HTTP method used by the endpoint.

path (str):

The relative path of the API endpoint.

request_params (Optional[_RequestParamsT]):

Query parameters for the request.

request_body (Optional[_RequestBodyT]):

The request body.

result_item_class (Type[_ResultItemT]):

Pydantic model for the expected response item.

result_class (Type[_ResultT]):

Pydantic model for the expected response result.

http_client (HTTPClient):

The HTTP client to send requests.

_request_params_class: Type[gfwapiclient.http.models.request._RequestParamsT] = None
_request_body_class: Type[gfwapiclient.http.models.request._RequestBodyT] = None
_result_item_class: Type[gfwapiclient.http.models.response._ResultItemT] = None
_result_class: Type[gfwapiclient.http.models.response._ResultT] = None
property headers: Dict[str, str]

Custom endpoint request headers.

Returns:
Dict[str, str]:

A dictionary containing custom headers for the request.

_prepare_request_method() str

Prepare the endpoint’s HTTP method (e.g., GET, POST, PUT, DELETE) for the request.

Returns:
str:

The endpoint’s HTTP method as a string.

_prepare_request_path() str

Prepare the endpoint’s path for the request.

Returns:
str:

The endpoint’s path as a string.

_prepare_request_url() httpx.URL

Prepare the endpoint’s full HTTP URL for the request.

Merges the endpoint’s path with the HTTPClient’s base_url to create the request URL.

Returns:
httpx.URL:

The endpoint’s full HTTP URL as an httpx.URL object.

_prepare_request_headers() httpx.Headers

Prepare the endpoint’s HTTP request headers for the request.

Returns:
httpx.Headers:

The endpoint’s HTTP request headers as an httpx.Headers object.

_prepare_request_query_params() Optional[httpx.QueryParams]

Prepare the endpoint’s HTTP request query parameters for the request.

Returns:
Optional[httpx.QueryParams]:

The endpoint’s HTTP request query parameters as an httpx.QueryParams object, or None if no query parameters are present.

_prepare_request_json_body() Optional[Dict[str, Any]]

Prepare HTTP request JSON body for the request.

_build_request() httpx.Request

Build and return an httpx.Request instance for this endpoint.

Returns:
httpx.Request:

An httpx.Request instance representing the HTTP request.

abstractmethod async request(**kwargs: Any) gfwapiclient.http.models.response._ResultT

Send an HTTP request for this endpoint.

Args:
**kwargs (Any):

Additional keyword arguments to pass to the httpx.Client.send() method.

Returns:
_ResultT:

The result of the API request as a _ResultT instance.