OBM 2 API Notebook

API quick reference

This notebook focuses on browse queries and low-level request/response handling. Most-used entry points:

  1. API.browse(...)

  2. API.send(...)

  3. HTTPSession()

  4. Request(...)

  5. Request.full

For the complete reference, see API Reference.

API methods used in this notebook

class here_search_demo.api.API(credentials=None, cache=None, raise_for_status=True, options=None, log_fn=None, on_request_sent=None, testing_header=False)

https://docs.here.com/geocoding-and-search/reference

async browse(session, latitude, longitude, categories=None, food_types=None, chains=None, polyline=None, width=None, all_along=None, x_headers=None, **kwargs)

Calls HERE Search Browse endpoint

Parameters:
  • session (ClientSession) – instance of HTTPSession

  • latitude (float) – search center latitude

  • longitude (float) – search center longitude

  • categories (Sequence[str] | None) – Places category ids for filtering

  • food_types (Sequence[str] | None) – Places cuisine ids for filtering

  • chains (Sequence[str] | None) – Places chain ids for filtering

  • x_headers (dict | None) – Optional X-* headers (X-Request-Id, X-AS-Session-ID, …)

Param:

kwargs: additional request URL parameters

Return type:

Response

Returns:

a Response object

async send(session, method, request)

Returns from HERE Search backend the response for a specific Request, or from the cache if it has been cached. Cache the Response if returned by the HERE Search backend.

Parameters:
  • session (ClientSession) – instance of ClientSession

  • request (Request) – Search Request object

Return type:

Response

Returns:

a Response object

class here_search_demo.lite.HTTPSession(*args, warmup=None, **kwargs)

Browser runtime HTTP session adapter.

Uses pyfetch in Pyodide/JupyterLite and mimics the subset of the aiohttp.ClientSession interface used by this project (get, post, and request).

Reference: https://pyodide.org/en/stable/usage/api/python-api/http.html

Examples (illustrative):

Basic GET:

async def demo_get(url):
    session = await HTTPSession()
    get_response = await session.get(url)
    get_response.raise_for_status()
    return await get_response.json()

Context-managed GET:

async def demo_ctx_get(url):
    async with HTTPSession() as session:
        async with session.get(url) as get_response:
            get_response.raise_for_status()
            return await get_response.json()

Reading bytes (e.g. image):

async def demo_read(image_url):
    async with HTTPSession() as session:
        async with session.get(image_url) as get_response:
            return await get_response.read()

Basic POST:

async def demo_post(url):
    async with HTTPSession() as session:
        async with session.post(url) as post_response:
            post_response.raise_for_status()
            return await post_response.text()

here_search_demo.http.HTTPSession resolves to this implementation in browser runtimes (JupyterLite / Pyodide).

class here_search_demo.entity.request.Request(endpoint=None, base_url=None, params=None, data=None, x_headers=None, previous_response=None)

Normalized HERE Search request payload.

Variables:
  • endpoint – target HERE Search endpoint enum

  • base_url – endpoint base URL

  • params – query-string parameters

  • data – optional request body (used for POST route payloads)

  • x_headers – optional request-scoped X-* headers

  • previous_response – optional previous response used for follow-up flows

property full

Return full request URL including encoded query string.

Returns:

full request URL

property key: str

Return a deterministic cache key for this request.

Returns:

cache key string derived from base URL and params

class here_search_demo.entity.response.Response(req, data, x_headers=<factory>, raw=None)

Immutable HERE Search response wrapper.

Variables:
  • req – originating request

  • data – parsed JSON payload view

  • x_headers – captured response X-* headers

  • raw – optional raw response body