Skip to content
Snippets Groups Projects
Commit 9d65ac11 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion :recycle:
Browse files

add endpoint to obtain detailed info from kegg through togows

parent db3e5157
No related branches found
No related tags found
2 merge requests!59Prod,!18Resolve "Create backend service to perform request to external APIs"
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 = [ urlpatterns = [
url(r'^togows/$', ListUsers.as_view()), path(r'togows/<kegg_id>', KeggInfoTogows.as_view(), name='kegg-info'),
] ]
from .togows import KeggInfoTogows # noqa
from bioapi.togows import TogoWSEntryAPI
from requests.exceptions import HTTPError
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.response import Response 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. Return a list of all users.
""" """
usernames = [user.username for user in User.objects.all()] kegg_api = TogoWSEntryAPI("kegg-orthology")
return Response(usernames) 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)
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