Self hosted FLOSS fitness/workout, nutrition and weight tracker
Further update the API documentation and the changelog
Roland Geiderd92ed27ec80c
diff --git a/wger/core/templates/rest_framework/api.html b/wger/core/templates/rest_framework/api.htmlindex 3ecdc9491..d52f9ff20 100644--- a/wger/core/templates/rest_framework/api.html+++ b/wger/core/templates/rest_framework/api.html@@ -161,8 +161,8 @@{% block sidebar %}<h4>Info</h4>-<p>This live browsing template was copied and adapted from- <a href="http://www.django-rest-framework.org/">Django REST framework</a>, who also- powers the API behind the scenes.+<p>This live browsing view was copied and adapted from+ <a href="http://www.django-rest-framework.org/">Django REST framework</a>,+ who also powers the API behind the scenes.</p>{% endblock %}diff --git a/wger/core/templates/user/api_key.html b/wger/core/templates/user/api_key.htmlindex 1e47b4d93..d8802abb6 100644--- a/wger/core/templates/user/api_key.html+++ b/wger/core/templates/user/api_key.html@@ -33,7 +33,8 @@ Authorization: Token {% if token %}{{token.key}}{% else %}1234567890abcde...{% e# Example with curl-curl -X GET https://wger.de/api/v2/workout/ -H 'Authorization: Token {% if token %}{{token.key}}{% else %}1234567890abcde...{% endif %}'+curl -X GET https://wger.de/api/v2/workout/ \+ -H 'Authorization: Token {% if token %}{{token.key}}{% else %}1234567890abcde...{% endif %}'</pre>{% endblock %}diff --git a/wger/software/templates/api.html b/wger/software/templates/api.htmlindex f88909f8b..66304bec2 100644--- a/wger/software/templates/api.html+++ b/wger/software/templates/api.html@@ -31,9 +31,9 @@ it in the header, see the link on the sidebar for details.</p><li>ingredient</li><li>ingredienttoweightunit</li><li>language</li>+ <li>license</li><li>muscle</li><li>weightunit</li>- <li>license</li></ul></div><div class="col-md-6">@@ -56,6 +56,37 @@ it in the header, see the link on the sidebar for details.</p></div>+<h3>Format negotiation</h3>+<p>+ At the moment only JSON and the browsable HTML view are supported, but other+ formats such as YAML or XML could be theoretically be added, should the+ need arise. Because of this, for the majority of REST clients it will not be+ necessary to explicitly set the format, but you have the following options:+</p>+<ul>+ <li>Set the <strong>Accept</strong> header:+ <ul>+ <li><code>application/json</code></li>+ <li>+ <code>application/json; indent=4</code> - useful for debugging, will+ indent the result+ </li>+ <li>+ <code>text/html</code> - browsable HTML view+ </li>+ </ul>+ </li>+ <li>+ Set the format <strong>directly in the URL</strong>:+ <ul>+ <li><code>/api/v2/<endpoint>/.json</code></li>+ <li>+ <code>/api/v2/<endpoint>/.api</code> - browsable HTML view+ </li>+ </ul>+ </li>+</ul>+<h3>Fetching Data</h3>@@ -109,26 +140,30 @@ it in the header, see the link on the sidebar for details.</p><p>You can easily filter all resources by specifying the filter queries in theURL: <code>?<fieldname>=<value></code>, combinations are possible,- just separate the filters with a comma: <code>?<f1>=<v1>,<f2>=<v2></code>.+ the filters will be AND-joined: <code>?<f1>=<v1>&<f2>=<v2></code>.Please note that for boolean values you must pass 'False' or 'True' othervalues, e.g. 1, 0, false, etc. will be ignored. Like with not filtered queries,your objects will be available under the 'results' key.</p><p>- It is not possible to specify more than one value, e.g. category 1 or 2.- To achieve this, just repeat the filter. See example below.+ Note that it is not currently possible to specify more than one value, e.g.+ category 1 or 2.</p><p>Some examples:</p><ul><li>All exercises in German: <code>api/v2/exercise/?language=1</code></li><li>'Main' image for all exercises: <code>api/v2/exerciseimage/?is_main=True</code></li>- <li>Exercises that train the biceps or the triceps:- <code>api/v2/exercise/?muscles=1&muscles=5</code>+ <li>Exercises that train the biceps with barbells: <code>api/v2/exercise/?muscles=1&equipment=3</code></li></ul>-+<h4>Submitting exercise images</h4>+<p>+ If you want to submit exercise pictures, remember that you have to set the+ correct header <code>Content-Type: multipart/form-data</code>, otherwise the+ file upload won't work.+</p><h3>Special endpoints</h3>@@ -265,6 +300,38 @@ the images to download a bigger version.</p>+<h3>Tools</h3>+<p>+ You can play and experiment with the API by sending the requests with many+ tools, here are two:+</p>++<pre>+# In the terminal, e.g. bash+curl -H "Authorization: Token 123456..." \+ -H "Accept: application/json; indent=4" \+ -X PATCH --data '{"key": value, ...}' \+ --dump-header -+ https://wger.de/api/v2/....+</pre>++<pre>+# In the python console+>>> import requests+>>> import json+>>> from pprint import pprint+>>>+>>> url = 'https://wger.de/api/v2/....'+>>> data = '{"key": "value"}'+>>> headers = {'Accept': 'application/json',+ 'Authorization': 'Token 12345...'}+>>> r = requests.patch(url=url, data=data, headers=headers)+>>> r+>>> r.content+>>> pprint(json.loads(r.content))+</pre>++<h3>/api/v1</h3><div class="panel panel-warning"><div class="panel-heading">diff --git a/wger/software/templates/changelog.html b/wger/software/templates/changelog.htmlindex 85b9dc7d2..d96d227cd 100644--- a/wger/software/templates/changelog.html+++ b/wger/software/templates/changelog.html@@ -13,6 +13,14 @@<ul><li>New Translation: Dutch (many thanks to David Machiels!)</li><li>Reduce amount of CSS and JS libraries by using bootstrap as much as possible</li>+ <li>Improvements to the REST API+ <ul>+ <li>Add read-write access</li>+ <li>Add live browsing of the API with django rest framework</li>+ <li>Improve documentation</li>+ <li>/api/v1 is marked deprecated</li>+ </ul>+ </li></ul>