<commit_before>====
APIs
====

When you have multiple Publishers collected together, it can be handy to publish them under the same path.  This is where the Api class comes in.

.. code-block:: python

    api = Api('name')

    api.register(MyPublisher)
    api.register(OtherPublisher, 'friendlyname')

By default, each Publisher will be registered with the name in its "api_name" property.

Once registered, you can get a list of URL patterns to include:

.. code-block:: python

    (r'^api/', include(api.patterns())),

When you add the patterns, you can optionally pass a 'flat' argument, which will omit the Api's name from the url patterns.

Also, the Api class provides an introspection view that will list all its Publishers, as well as their handlers and methods supported.

Auto-discover
-------------

Just like Django's Admin, Api supports auto-discover.

In your publishers.py use:

.. code-block:: python

    from nap import api

    ...

    api.register('apiname', Publisher,....)

An Api instance with that name will be created, if it hasn't already, and put into api.APIS.  Then the publisher(s) you pass will be registered with it.

Then, in your urls.py, just add:

.. code-block:: python

    from nap import api
    api.autodiscover()

Which will trigger it to import $APP.serialiser from each of your INSTALLED_APPS.  Then you can just include the urls:

.. code-block:: python

    (r'^apis/', include(api.patterns()))

<commit_msg>Clarify use of api_name with API<commit_after>====
APIs
====

When you have multiple Publishers collected together, it can be handy to
publish them under the same path.  This is where the Api class comes in.

.. code-block:: python

    api = Api('name')

    api.register(MyPublisher)
    api.register(OtherPublisher, 'friendlyname')

If not overridden by being passed in the call to register, the Publisher will
be registered with the name in its ``api_name`` property.  This is used as the
root of its URL within the Api.

Once registered, you can get a list of URL patterns to include:

.. code-block:: python

    (r'^api/', include(api.patterns())),

When you add the patterns, you can optionally pass a 'flat' argument, which
will omit the Api's name from the url patterns.

Also, the Api class provides an introspection view that will list all its
Publishers, as well as their handlers and methods supported.

Auto-discover
-------------

Just like Django's Admin, Api supports auto-discover.

In your publishers.py use:

.. code-block:: python

    from nap import api

    ...

    api.register('apiname', Publisher,....)

An Api instance with that name will be created, if it hasn't already, and put
into api.APIS.  Then the publisher(s) you pass will be registered with it.

.. note::

   Publishers registered this way *must* have an ``api_name`` property defined.

Then, in your urls.py, just add:

.. code-block:: python

    from nap import api
    api.autodiscover()

Which will trigger it to import $APP.serialiser from each of your
INSTALLED_APPS.  Then you can just include the urls:

.. code-block:: python

    (r'^apis/', include(api.patterns()))


{'fraction_non_alphanumeric': 0.09776357827476038, 'fraction_numerical': 0.0, 'mean_word_length': 3.453769559032717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1816107', 'n_tokens_mistral': 934, 'n_tokens_neox': 892, 'n_words': 421}