Skip to content
Snippets Groups Projects
Commit d82c6522 authored by Jonathan Seguin's avatar Jonathan Seguin
Browse files

Add graphql example to /api. Simplify auth code

parent 39677537
No related tags found
1 merge request!77Resolve "Explore GraphQL as separate API"
......@@ -4,9 +4,8 @@ from django.contrib.auth.models import User
class TokenAuthBackend(ModelBackend):
def authenticate(self, request, token=None):
if not token and 'headers' in request:
if not token:
token = request.headers.get('Iric-Auth-Token')
try:
return User.objects.get(profile__api_token=token)
except User.DoesNotExist:
......
......@@ -16,8 +16,12 @@
</div>
<p>
{% trans 'Use this token to authenticate your API calls by inserting it in the request header under "Iric-Auth-Token".' %}
Ex.
</p>
<p>
{% trans 'Two APIs exists to query IRIC Data :' %}
</p>
<h3> {% trans 'IRIC Data API v1 (python requests example)' %} </h3>
<div class="col-10 alert alert-secondary">
<pre class='mb-0'><code>import requests
url = '{{ request.scheme }}://{{ request.get_host }}/api/v1/my-datasets/list/json/'
......@@ -25,6 +29,24 @@ headers = {'Iric-Auth-Token': '{{user.profile.api_token}}'}
r = requests.get(url, headers=headers)
r.json()</code></pre>
</div>
<h3> {% trans 'GraphQL API (python requests example)' %} </h3>
<p>
<i>{% trans 'NOTE: A GraphQL sandbox is also available online' %} : <a href="{{ request.scheme }}://{{ request.get_host }}/graphql/">{{ request.scheme }}://{{ request.get_host }}/graphql/<a></i>
</p>
<div class="col-10 alert alert-secondary">
<pre class='mb-0'><code>import requests
url = '{{ request.scheme }}://{{ request.get_host }}/graphql/'
headers = {'Iric-Auth-Token': '{{user.profile.api_token}}'}
query = """{
datafiles {
filename
}
}
"""
r = requests.post(url, headers=headers, json={'query': query})
r.json()</code></pre>
</div>
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment