Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Some improvements to API documentation

Roland Geider287c2bb04d9e
diff --git a/wger/manager/templates/user/api_key.html b/wger/manager/templates/user/api_key.html
index 87929506e..bafbe8909 100644
--- a/wger/manager/templates/user/api_key.html
+++ b/wger/manager/templates/user/api_key.html
@@ -9,17 +9,17 @@
{% block content %}
<p>{% blocktrans %}Generate an API key if you want to interact with wger via
-the <a href="/api/v1/?format=json" rel="nofollow">REST api</a> it provides (for public resources
-such as the exercises or ingredients, you don't need to provide anything). You
-must pass this information together with your username either in the header or
-in the request as GET parameters. For example:{% endblocktrans %}
+the <a href="/api/v1/?format=json" rel="nofollow">REST API</a> it provides (for
+public resources such as the exercises or ingredients, you don't need to provide
+anything). You must pass this information together with your username either in
+the header or in the request as GET parameters. For example:{% endblocktrans %}
<pre>
# In header
Authorization: ApiKey myusername:1234567890abcde...
# In GET parameter
-https://wger.de/api/v1/foo/?username=myusername&api_key=1234567890abcde...
+https://wger.de/api/v1/workout/?username=myusername&api_key=1234567890abcde...
</pre>
</p>
@@ -64,4 +64,9 @@ https://wger.de/api/v1/foo/?username=myusername&api_key=1234567890abcde...
</p>
+
+<p>
+ <a href="{% url 'software:api' %}" class="btn btn-block">{% trans 'Documentation' %}</a>
+</p>
+
{% endblock %}
diff --git a/wger/software/templates/api.html b/wger/software/templates/api.html
index d4610576f..8943050e2 100644
--- a/wger/software/templates/api.html
+++ b/wger/software/templates/api.html
@@ -7,22 +7,28 @@
{% block title %}{% trans "REST API" %}{% endblock %}
{% block content %}
+{% with link='href="/api/v1/?format=json" rel="nofollow"' %}
<p>{% blocktrans %}wger Workout Manager provides a full REST API to all database
-objects:{% endblocktrans %} <a href="/api/v1/?format=json" rel="nofollow">/api/v1/</a>
-</p>
-
-<p>{% blocktrans %}Public endpoints, such as the list of exercises or the
-ingredients can be accessed without authentication. For user owned
-objects such as workouts, you need to generate an API KEY and pass it
-along with the username either in the header or in form of GET parameters.
-See the link on the sidebar for details. You should always use HTTPS when
-communicating with the server.{% endblocktrans %}</p>
+objects:{% endblocktrans %} <a {{link}}>https://wger.de/api/v1/</a></p>
+{% endwith %}
<p>{% blocktrans %}The API uses HATEOAS, so you should be able to browse
through the necessary endpoints without having to consult an extensive
documentation. At the moment, the API only supports read operations, but
support for full POST/PUT/DELETE/PATCH is planned for the near future.{% endblocktrans %}</p>
+<p>{% blocktrans %}You should always use HTTPS if possible when communicating
+with the server.{% endblocktrans %}</p>
+
+
+<h3>{% trans "Authentication" %}</h3>
+<p>{% blocktrans %}Public endpoints, such as the list of exercises or the
+ingredients can be accessed without authentication. For <strong>user owned
+objects such as workouts, you need to generate an API KEY</strong> and pass
+it along with the username either in the header or in form of GET parameters.
+See the link on the sidebar for details.{% endblocktrans %}</p>
+
+
<h3>{% trans "Fetching Data" %}</h3>
@@ -33,19 +39,19 @@ https://django-tastypie.readthedocs.org/en/latest/interacting.html
<h4>Api-Wide</h4>
<code>
-curl https://wger.de/api/v1/
+curl https://wger.de/api/v1/ | python -m json.tool
</code>
-<p>{% blocktrans %}This lists out all the different resources available. Each one
-is listed by the resource_name and provides the list_endpoint and the schema
-for the resource. Note that these links try to direct you to other parts of
-the API, to make exploration/discovery easier.{% endblocktrans %}</p>
+<p>{% blocktrans %}This lists out all the different resources available. Each
+one is listed by the resource_name and provides the list_endpoint and the schema
+for the resource. Note that these links try to direct you to other parts of the
+API, to make exploration/discovery easier.{% endblocktrans %}</p>
-<h4>{% trans "Getting A Collection Of Resources" %}</h4>
+<h4>{% trans "Getting A Collection Of Resources" %}</h4>
<code>
-curl https://wger.de/api/v1/foobar/
-curl https://wger.de/api/v1/foobar/schema/
+curl https://wger.de/api/v1/exercise/ | python -m json.tool
+curl https://wger.de/api/v1/exercise/schema/ | python -m json.tool
</code>
@@ -58,22 +64,23 @@ curl https://wger.de/api/v1/foobar/schema/
</ul>
<code>
-curl https://wger.de/api/v1/foobar/1/
+curl https://wger.de/api/v1/exercise/1/ | python -m json.tool
</code>
-<p>{% blocktrans %}This simply returns the foobar resource with the ID 1.{% endblocktrans %}</p>
+<p>{% blocktrans %}This simply returns the exercise resource with the ID 1.{% endblocktrans %}</p>
<code>
-curl https://wger.de/api/v1/foobar/1/?bar=baz
-curl https://wger.de/api/v1/foobar/set/1;3/
-curl https://wger.de/api/v1/foobar/?offset=20&limit=20
+curl https://wger.de/api/v1/foobar/1/?bar=baz | python -m json.tool
+curl https://wger.de/api/v1/exercise/set/1;3/ | python -m json.tool
+curl https://wger.de/api/v1/exercise/?offset=20&limit=20 | python -m json.tool
</code>
-<p>{% blocktrans %}You can filter the resources, assuming that bar is an attribute
-of foobar. Alternatively you can just specify the IDs you need or provide an offset.{% endblocktrans %}</p>
+<p>{% blocktrans %}You can filter the resources, assuming that bar is an
+attribute of foobar. Alternatively you can just specify the IDs you need or
+provide an offset.{% endblocktrans %}</p>
+{% endblock %}
-{% endblock %}
{% block sidebar %}
<div class="alert alert-info" style="margin-top:1em;">