{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load wger_extras %}


{% block title %}{% trans "REST API" %}{% endblock %}

{% block content %}
<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>

<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>



<h3>{% trans "Fetching Data" %}</h3>
<!--
Many of the explanations are taken from
https://django-tastypie.readthedocs.org/en/latest/interacting.html
-->

<h4>Api-Wide</h4>
<code>
curl https://wger.de/api/v1/
</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>

<h4>{% trans "Getting A Collection Of Resources" %}</h4>

<code>
curl https://wger.de/api/v1/foobar/
curl https://wger.de/api/v1/foobar/schema/
</code>


<ul>
    <li>{% trans "By default, you get a paginated set of objects" %}</li>
    <li>{% trans "In the meta, you get a previous and next. If available, these are URIs to the previous and next pages." %}</li>
    <li>{% trans "You get a list of resources/objects under the objects key." %}</li>
    <li>{% trans "Each resources/object has a resource_uri field that points to the detail view for that object." %}</li>
    <li>{% trans "Foreign keys are represented as URIs." %}</li>
</ul>

<code>
curl https://wger.de/api/v1/foobar/1/
</code>

<p>{% blocktrans %}This simply returns the foobar 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
</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>



{% endblock %}

{% block sidebar %}
<div class="alert alert-info" style="margin-top:1em;">
{% blocktrans %}This is also new for us, if you plan on using the API,
<a href="https://groups.google.com/group/wger">we'd love to hear from you</a>.{% endblocktrans %}
</div>

<p><a href="/api/v1/?format=json" class="btn btn-block">{% trans "Browse the API" %}</a></p>
<p><a href="{% url 'api-key' %}" class="btn btn-block">Generate API KEY</a></p>
{% endblock %}
