Internal API¶
A library to allow navigating rest apis easy.
-
class
restnavigator.halnav.
APICore
(root, nav_class, apiname=None, default_curie=None, session=None, id_map=None)[source]¶ Shared data between navigators from a single api.
This should contain all state that is generally maintained from one navigator to the next.
-
cache
(link, nav)[source]¶ Stores a navigator in the identity map for the current api. Can take a link or a bare uri
-
-
class
restnavigator.halnav.
HALNavigator
(link, core, response=None, state=None, curies=None, _links=None, _embedded=None)[source]¶ The main navigation entity
-
create
(body=None, raise_exc=True, headers=None, **kwargs)[source]¶ Performs an HTTP POST to the server, to create a subordinate resource. Returns a new HALNavigator representing that resource.
body may either be a string or a dictionary representing json headers are additional headers to send in the request
-
delete
(raise_exc=True, headers=None, files=None)[source]¶ Performs an HTTP DELETE to the server, to delete resource(s).
headers are additional headers to send in the request
-
patch
(body, raise_exc=True, headers=False, files=None)[source]¶ Performs an HTTP PATCH to the server. This is a non-idempotent call that may update all or a portion of the resource this navigator is pointing to. The format of the patch body is up to implementations.
body may either be a string or a dictionary representing json headers are additional headers to send in the request
-
upsert
(body, raise_exc=True, headers=False, files=None)[source]¶ Performs an HTTP PUT to the server. This is an idempotent call that will create the resource this navigator is pointing to, or will update it if it already exists.
body may either be a string or a dictionary representing json headers are additional headers to send in the request
-
-
class
restnavigator.halnav.
HALNavigatorBase
(link, core, response=None, state=None, curies=None, _links=None, _embedded=None)[source]¶ Base class for navigation objects
-
class
restnavigator.halnav.
Link
(uri, properties=None)[source]¶ Represents a HAL link. Does not store the link relation
-
class
restnavigator.halnav.
Navigator
[source]¶ A factory for other navigators. Makes creating them more convenient
-
class
restnavigator.halnav.
OrphanHALNavigator
(link, core, response=None, state=None, curies=None, _links=None, parent=None)[source]¶ A Special navigator that is the result of a non-GET
This navigator cannot be fetched or created, but has a special property called .parent that refers to the navigator this one was created from. If the result is a HAL document, it will be populated properly
-
class
restnavigator.halnav.
PartialNavigator
(link, core=None)[source]¶ A lazy representation of a navigator. Expands to a full navigator when template arguments are given by calling it.
-
expand_link
(**kwargs)[source]¶ Expands with the given arguments and returns a new untemplated Link object
-
variables
¶ Returns a set of the template variables in this templated link
-
-
exception
restnavigator.exc.
HALNavigatorError
(message, nav=None, status=None, response=None)[source]¶ Raised when a response is an error
Has all of the attributes of a normal HALNavigator. The error body can be returned by examining response.body
-
exception
restnavigator.exc.
NoResponseError
[source]¶ Raised when accessing a field of a navigator that has not fetched a response yet
-
exception
restnavigator.exc.
OffTheRailsException
(traversal, index, intermediates, e)[source]¶ Raised when a traversal specified to __getitem__ cannot be satisfied
-
exception
restnavigator.exc.
UnexpectedlyNotJSON
(uri, response)[source]¶ Raised when a non-json parseable resource is gotten
-
class
restnavigator.utils.
CurieDict
(default_curie, d)[source]¶ dict subclass that allows specifying a default curie. This enables multiple ways to access an item
-
class
restnavigator.utils.
LinkList
(items=None)[source]¶ A list subclass that offers different ways of grabbing the values based on various metadata stored for each entry in the dictionary.
Note: Removing items from this list isn’t really the point, so no attempt has been made to make this convenient. Deleting items will not remove them from the list’s metadata.
-
append_with
(obj, **properties)[source]¶ Add an item to the dictionary with the given metadata properties
-
get_by
(prop, val, raise_exc=False)[source]¶ Retrieve an item from the dictionary with the given metadata properties. If there is no such item, None will be returned, if there are multiple such items, the first will be returned.
-
serialize
¶ alias of
unicode
-
-
restnavigator.utils.
fix_scheme
(url)[source]¶ Prepends the http:// scheme if necessary to a url. Fails if a scheme other than http is used
-
restnavigator.utils.
getpath
(d, json_path, default=None, sep='.')[source]¶ Gets a value nested in dictionaries containing dictionaries. Returns the default if any key in the path doesn’t exist.
-
restnavigator.utils.
getstate
(d)[source]¶ Deep copies a dict, and returns it without the keys _links and _embedded
-
restnavigator.utils.
namify
(root_uri)[source]¶ Turns a root uri into a less noisy representation that will probably make sense in most circumstances. Used by Navigator’s __repr__, but can be overridden if the Navigator is created with a ‘name’ parameter.
-
restnavigator.utils.
normalize_getitem_args
(args)[source]¶ Turns the arguments to __getitem__ magic methods into a uniform list of tuples and strings
-
restnavigator.utils.
objectify_uri
(relative_uri)[source]¶ Converts uris from path syntax to a json-like object syntax. In addition, url escaped characters are unescaped, but non-ascii characters a romanized using the unidecode library.
- Examples:
- “/blog/3/comments” becomes “blog[3].comments” “car/engine/piston” becomes “car.engine.piston”