Proper URL patterns are the backbone of a ResourceModel. URLs are defined in a ResourceModel as a tuple of nap_urls–a thin wrapper around a python-formatted string. These are defined and tied to a ResourceModel through the urls, prepend_urls, and append_urls. These are stored in the ResourceModel’s _meta
By default, ResourceModels have two nap_urls that allow them to make all common calls to a to-spec REST API:
( nap_url('%(resource_name)s/', create=True, lookup=False, collection=True), nap_url('%(resource_name)s/%(resource_id)s/', update=True), )
nap_urls contain three parts of information:
On calls that are backed by a URL, Nap will iterate through every URL in it’s url list looking for a match. A match is considered a URL where
Let’s dive into each part of a URL to understand this process a bit better.
Lookup types closely match the kind of operations possible with an API. They are create, lookup, update, collection.
A URL string is simply a python string, optionally containing dictionary-format variables.
nap bases it’s required variables partially on any format variables contained in the URL string.
LookupURLs may require variables to fully resolve. Required variables are either
ResourceModel passes in three kinds of variables into the LookupURL’s match function to determine if all required variables are available for URL resolution:
The above lists these groups in order of presidence–eg, If update() is called on a ResourceModel with a resource_name of ‘person’, but a keyword argument of resource_name='author', %(resource_name)s will resolve to author.
Currently, there is only one meta variable passed to LookupURL.
Class in charge of resolving variable URLs based on keyword arguments. Used for any dynamic API method on ResourceModel
Returns a tuple the names of variables contained within a LookupURL
Returns a tuple of the the names of all variables required to successfully resolve a URL.
Attempts to resolve a string of a URL, resolving any variables based on lookup_vars.
Returns a two tuple of the matching URL string and extra lookup variables that were passed in but not part of the required values.
If no match is found, a two tuple of (None, None) is returned.
|Parameters:||lookup_vars – A dict-like variable mapping URL variables names to|