File: access-service-with-api-proxy.rst

package info (click to toggle)
python-pykube-ng 22.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: python: 2,336; makefile: 44
file content (15 lines) | stat: -rw-r--r-- 603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
=======================
How to access a Service
=======================

To access the service defined with your ``Service`` object, you can use the HTTP proxy provided by the API server.
There are convenience methods to do ``GET``, ``POST``, ``PUT`` and ``DELETE`` and the generic ``proxy_http_request`` version,
where you can pass any HTTP verb.

.. code-block:: python

    service = pykube.Service.objects(api).filter(namespace="default").get(name="test")
    res = service.proxy_http_get("my/path")
    assert res is not None
    assert res.content == b"it works"
    assert res.status_code == 200