Skip to content

Commit 04d6981

Browse files
committed
docs: document dashes and .url
1 parent 7d4ecb3 commit 04d6981

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

docs/02-making-calls.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ The ``kwargs`` are used to add query parameters to the URL. The ``data`` and ``f
3333
are used to add a payload to the request. See :py:meth:`requests.Session.request` for more
3434
information on the allowed values for these parameters.
3535

36+
.. note::
37+
38+
If you have a doubt or want to play with the URL mapping behavior without doing any real call,
39+
use the special method ``.url()``. It will return the translated URL, with no side effect!
40+
41+
Spin up a Python shell and try it out right now:
42+
43+
.. testcode::
44+
45+
from mantelo import KeycloakAdmin
46+
c = KeycloakAdmin("https://invalid.com", "my-realm", None)
47+
url = c.just_trying.some("mapping").url()
48+
print(url)
49+
50+
Yields:
51+
52+
.. testoutput::
53+
54+
https://invalid.com/admin/realms/my-realm/just-trying/some/mapping
55+
56+
(Parameters themselves are handled by :py:mod:`requests`).
3657

3758
To better understand, here are some examples of URL mapping (``c`` is the
3859
:py:class:`~.KeycloakAdmin` object):
@@ -74,10 +95,30 @@ To better understand, here are some examples of URL mapping (``c`` is the
7495
> Content-Type: application/json
7596
> {"username": ...}
7697
98+
About dashes
99+
------------
100+
101+
Since Python doesn't allow dashes in method names, but Keycloak URLs use them in some places,
102+
Mantelo automatically converts any underscores in method names to dashes in the URL.
103+
104+
In other words, to call:
105+
106+
.. code-block:: none
107+
108+
GET /admin/realms/{realm}/client-scopes
109+
110+
You can use:
111+
112+
.. code-block:: python
113+
114+
c.client_scopes.get()
115+
116+
Note that you could also use ``c("client-scopes").get()``, but let's admit it, it is ugly (so
117+
don't).
118+
77119
Special case: working with realms
78120
---------------------------------
79121

80-
81122
By default, a client is bound to a realm, and has the base URL set to
82123
``<server-url>/admin/realms/<realm-name>``. Hence, to query ``GET /admin/realms/<realm-name>``, you
83124
can use :python:`c.get()` directly (or :python:`c.post({})` to update its properties).

docs/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Mantelo: A Keycloak Admin REST Api Client for Python
1212

1313
It stays always **fresh** and **complete** because it does not implement or wrap any endpoint.
1414
Instead, it offers an object-oriented interface to the Keycloak ReSTful API. Acting as a wrapper
15-
around the well-known `requests <https://requests.readthedocs.io/en/latest/>`_ library and using
16-
slumber under the hood, it abstracts all the boring stuff such as authentication (tokens and refresh
17-
tokens), URL handling, serialization, and the processing of requests. This magic is made possible by
18-
the excellent `slumber <https://slumber.readthedocs.io/>`_ library.
15+
around the well-known `requests <https://requests.readthedocs.io/en/latest/>`_ library, it abstracts
16+
all the boring stuff such as authentication (tokens and refresh tokens), URL handling,
17+
serialization, and the processing of requests. This magic is made possible by the excellent
18+
`slumber <https://slumber.readthedocs.io/>`_ library.
1919

2020
⮕ Any endpoint your Keycloak supports, mantelo supports!
2121

0 commit comments

Comments
 (0)