Commit 9d65ac11 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

add endpoint to obtain detailed info from kegg through togows

parent db3e5157
Pipeline #18235 passed with stages
in 2 minutes and 26 seconds
from django.conf.urls import url
from django.urls import path
from metagenedb.api.external.views.togows import ListUsers
from metagenedb.api.external.views import KeggInfoTogows
urlpatterns = [
url(r'^togows/$', ListUsers.as_view()),
path(r'togows/<kegg_id>', KeggInfoTogows.as_view(), name='kegg-info'),
]
from bioapi.togows import TogoWSEntryAPI
from requests.exceptions import HTTPError
from rest_framework.views import APIView
from rest_framework.response import Response
from django.contrib.auth.models import User
from rest_framework.status import (HTTP_200_OK, HTTP_404_NOT_FOUND)
class ListUsers(APIView):
class KeggInfoTogows(APIView):
"""
View to list all users in the system.
Obtain detailed information about KEGG orthology entry.
"""
def get(self, request, format=None):
def get(self, request, kegg_id=None):
"""
Return a list of all users.
"""
usernames = [user.username for user in User.objects.all()]
return Response(usernames)
kegg_api = TogoWSEntryAPI("kegg-orthology")
try:
content = kegg_api.get(kegg_id)[0]
status = HTTP_200_OK
except HTTPError as http_err:
content = [{'error': str(http_err)}]
status = HTTP_404_NOT_FOUND
return Response(content, status=status)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment