-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adiciona página com documentação da API #502
Open
berinhard
wants to merge
7
commits into
develop
Choose a base branch
from
feature/api-docs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3aeb6e4
Implementa docs dinâmicos para a API
berinhard c6443db
Adiciona link para docs no menu
berinhard 91f7ed5
âncora para sessão "datasets"
berinhard 7b46f3e
Atualiza URL
berinhard 793e77b
Recupera host de api do settings
berinhard fb96179
Simplifica rendericação dos campos removendo descrição e adicionando …
berinhard dadf8b0
Adiciona ícones sobre os campos
berinhard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.conf import settings | ||
from django.shortcuts import render | ||
|
||
from core.models import Dataset | ||
|
||
|
||
def dynamic_api_docs_view(request): | ||
context = { | ||
"datasets": Dataset.objects.api_visible(), | ||
"api_host": settings.BRASILIO_API_HOST, | ||
} | ||
return render(request, "api/docs.html", context=context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}Documentação da API{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<div class="section"> | ||
<div class="row"> | ||
<div class="col s12"> | ||
<div class="card"> | ||
<div class="card-content"> | ||
<p class="card-title">Documentação da API</p> | ||
<p>Aqui você pode encontrar a listagem de todos os datasets, tabelas e campos disponíveis na API do Brasil.io. Além disso, você também encontrará informações sobre como fazer requisições para a API respeitando a autenticação.</p> | ||
<p><b>Importante:</b> Utilizar a API desnecessariamente e de maneira não otimizada onera muito nossos servidores e atrapalha a experiência de outros usuários. Por conta disso, nessa documentação vocè também encontrará os links para os arquivos de dados completos de todos os datasets.</p> | ||
|
||
<br/> | ||
<p class="card-title">Índice</p> | ||
<ul> | ||
<li><a href="#autenticacao">Autenticação</a></li> | ||
<li><a href="#datasets">Datasets</a></li> | ||
{% for dataset in datasets %} | ||
<li><a href="#{{ dataset.slug }}">{{ dataset.name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<h3 id="autenticacao">Autenticação</h3> | ||
<hr> | ||
<p>Para ter mais contexto sobre os porquês dessa autenticação, leia o nosso blogpost <a href="https://blog.brasil.io/2020/10/31/nossa-api-sera-obrigatoriamente-autenticada/" target="_blank">"Nossa API será obrigatoriamente autenticada"</a>.</p> | ||
<p>A API do Brasil.IO implementa utilizando o <b>cabeçalho HTTP Authorizaton</b>. Ela espera que o valor desse cabeçalho seja sempre algo no formato <code>Token sua_chave_de_api_aqui</code>. Este é um exemplo de uma requisição para a raiz da API utilizando o Curl:</p> | ||
<p><code>curl -X GET -k -H 'Authorization: Token 123412341234' -i 'https://api.brasil.io/v1/'</code></p> | ||
<p>Para criar e gerenciar suas chaves de API, autentique-se no sistema e acesse a página <a href="{% url 'brasilio_auth:list_api_tokens' %}">Chaves da API</a>.</p> | ||
|
||
<h3 id="datasets">Datasets</h3> | ||
<hr> | ||
<p>Exemplo de requisição para listar todos os datasets disponíveis na API do Brasil.io:</p> | ||
<p><code>curl -X GET -k -H 'Authorization: Token 123412341234' -i 'https://{{ api_host }}/v1/datasets/'</code></p> | ||
|
||
{% for dataset in datasets %} | ||
{% include "api/snippets/dataset_docs.html" with dataset=dataset %} | ||
{% endfor %} | ||
|
||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<h4 id="{{ dataset.slug }}">{{ dataset.name }}</h4> | ||
<hr/> | ||
|
||
<p>Exemplo de requisição para apresentar informações sobre esse dataset:</p> | ||
<p><code>curl -X GET -k -H 'Authorization: Token 123412341234' -i 'https://{{ api_host }}/v1/dataset/{{ dataset.slug }}/'</code></p> | ||
<p>O <b>dataset completo</b> pode ser baixado diretamente <a href="{{ dataset.files_url }}">nesta página</a>. Por favor, dê preferência a baixar o dataset completo caso você vá precisar de todos aos dados ao invés de utilizar a API.</p> | ||
|
||
{% for table in dataset.tables %} | ||
{% if table.api_enabled %} | ||
<h5 id="{{ dataset.slug }}-{{ dataset.table }}">Tabela {{ table.name }}</h5> | ||
<p>Exemplo de requisição para os dados desta tabela:</p> | ||
<p><code>curl -X GET -k -H 'Authorization: Token 123412341234' -i 'https://{{ api_host }}/v1/dataset/{{ dataset.slug }}/{{ table.name }}/data/'</code></p> | ||
<h6>Colunas</h6> | ||
|
||
<ul class="table-fields"> | ||
{% for field in table.fields %} | ||
<li><code>{{ field.name }}</code> ({{ field.get_type_display }}) | ||
|
||
{% if field.show %} | ||
{% if field.show_on_frontend %}<i class="fa fa-eye" title="Esse campo é visível na interface Web, na API e no download completo"></i>{% endif %} | ||
{% if not field.show_on_frontend %}<i class="fa fa-low-vision" title="Esse campo não é visível na interface Web, apenas na API e no download completo"></i>{% endif %} | ||
{% else %} | ||
{% if not field.show_on_frontend %}<i class="fa fa-eye-slash" title="Esse campo é usado internamente e fica visível apenas no download completo"></i>{% endif %} | ||
{% endif %} | ||
|
||
{% if field.frontend_filter %}<i class="fa fa-filter" title="Você pode fazer filtros por esse campo na interface Web e na API"></i>{% endif %} | ||
|
||
{% if field.searchable %}<i class="fa fa-search" title="Você pode utilizar a busca de texto completo nesse campo"></i>{% endif %} | ||
|
||
{% if field.has_choices %}<i class="fa fa-list-ul" title="Esse campo possui valores categóricos"></i>{% endif %} | ||
|
||
: {{ field.title }} </li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O texto pode ser
Documentação da API
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quebra muito o layout colocar esse texto:
'