Skip to content

Commit 1d2ed9e

Browse files
claudertibbles
authored andcommitted
Add comprehensive documentation for URL namespacing
This commit adds extensive documentation for the URL namespacing system used throughout the Kolibri codebase, addressing issue #9435. Changes include: - New comprehensive how-to guide: "Working with URLs and API Endpoints" that covers: * URL naming conventions (kolibri:namespace:resource_endpoint) * How to define URLs in Django backend (ViewSets, routers, custom URLs) * How to use URLs in JavaScript frontend (direct access, API Resources) * Complete explanation of the backend-to-frontend URL pipeline * Best practices and debugging tips * Advanced topics (custom endpoints, direct endpoint access) - Updated existing API endpoints documentation with URL namespacing overview and cross-reference to the new guide - Updated frontend core architecture documentation to explain URL namespacing with practical examples - Added the new guide to the howtos index The documentation explains how URL namespacing works implicitly in the API resource layer and explicitly in frontend code (e.g., urls['kolibri:core:driveinfo-list']), providing developers with a complete understanding of the system. Fixes #9435 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent a071b71 commit 1d2ed9e

File tree

4 files changed

+554
-1
lines changed

4 files changed

+554
-1
lines changed

docs/backend_architecture/content/api_endpoints.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
API endpoints
22
-------------
33

4+
URL Namespacing
5+
~~~~~~~~~~~~~~~
6+
7+
Kolibri uses a consistent URL namespacing pattern throughout the codebase. All URLs follow the format:
8+
9+
>>> kolibri:<plugin_module>:<url_name>
10+
11+
Where ``<plugin_module>`` is either ``core`` for core Kolibri functionality (a special case, as core is not actually in a plugin module), or the full plugin module path (e.g., ``kolibri.plugins.coach``) for plugins.
12+
13+
For example:
14+
15+
>>> kolibri:core:session_list
16+
>>> kolibri:core:session_detail
17+
>>> kolibri:core:usernameavailable
18+
>>> kolibri:kolibri.plugins.coach:lessonreport_list
19+
>>> kolibri:kolibri.plugins.coach:lessonreport_detail
20+
21+
This namespacing is used both in Django backend URL configuration and in JavaScript frontend code.
22+
23+
For comprehensive information about URL namespacing, including how to define and use URLs in both backend and frontend code, see the :doc:`/howtos/working_with_urls_and_api_endpoints` guide.
24+
25+
Example Endpoints
26+
~~~~~~~~~~~~~~~~~
27+
428
request specific content:
529

630
>>> localhost:8000/api/content/<channel_id>/contentnode/<content_id>

docs/frontend_architecture/core.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,29 @@ Bootstrapped data
7979

8080
The ``kolibriCoreAppGlobal`` object is also used to bootstrap data into the JS app, rather than making unnecessary API requests.
8181

82-
For example, we currently embellish the ``kolibriCoreAppGlobal`` object with a ``urls`` object. This is defined by `Django JS Reverse <https://github.com/ierror/django-js-reverse>`__ and exposes Django URLs on the client side. This will primarily be used for accessing API Urls for synchronizing with the REST API. See the Django JS Reverse documentation for details on invoking the Url.
82+
For example, we currently embellish the ``kolibriCoreAppGlobal`` object with a ``urls`` object. This is defined by `Django JS Reverse <https://github.com/ierror/django-js-reverse>`__ and exposes Django URLs on the client side. This will primarily be used for accessing API Urls for synchronizing with the REST API.
83+
84+
URLs and API Endpoints
85+
~~~~~~~~~~~~~~~~~~~~~~
86+
87+
Kolibri uses a consistent URL namespacing pattern (e.g., ``kolibri:core:session_list``) that bridges Django's backend URL system with JavaScript frontend code. URLs can be accessed in JavaScript via the ``urls`` object:
88+
89+
.. code-block:: javascript
90+
91+
import urls from 'kolibri/urls';
92+
import client from 'kolibri/client';
93+
94+
// Call a list endpoint
95+
const response = await client({
96+
url: urls['kolibri:core:session_list'](),
97+
});
98+
99+
// Call a detail endpoint with a parameter
100+
const response = await client({
101+
url: urls['kolibri:core:session_detail'](sessionId),
102+
});
103+
104+
For comprehensive information about URL namespacing, including how to define URLs in Django and use them in JavaScript, see the :doc:`/howtos/working_with_urls_and_api_endpoints` guide.
83105

84106
Additional functionality
85107
------------------------

docs/howtos/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ These guides are step by step guides for common tasks in getting started and wor
1616
another_kolibri_instance
1717
development_with_kds
1818
preview_on_mobile
19+
working_with_urls_and_api_endpoints

0 commit comments

Comments
 (0)