JupyterLab extension to get info from hub api

I want to develop an extension for jupyterlab which gets users list from hub api and show it to the user to do something. I’m a bit confused about backend and frontend. I don’t know if I would be able to send http request from frontend to hub api and get the users list. Or do I have to do it in server side?

I would be happy if someone give me some explanation about extensions with server and client side. Most of the examples are only frontend extensions.

Thanks,

Hi @frouzbeh, I am also interested to do exactly this! I hope you had some progress since. If not, please let me outline my thoughts and if you are still interested we can continue discussion here.

  1. Send a request to JupyterHub API from backend
    This part is relatively easy to do on the backend. You need a token and API url. For eaxmple, I was able to get the username of the current user:
import requests

api_url = os.environ['JUPYTERHUB_API_URL']

r = requests.get(api_url + '/user',
    headers={
             'Authorization': 'token %s' % os.environ['JUPYTERHUB_API_TOKEN'],
            }
    )

r.raise_for_status()
user = r.json()
  1. To get the same information in the frontend, you will need to to either send the information from the backend or send the API key and API url and make a API request from the frontend. In either case, you will need to have both frontend and backend part of the extension. I do not yet know how to make the connection between the two, but there are a lot of extensions using this scheme so it should be possible to replicate.

Does anyone have experience in doing this? If not, I can post my next steps here, so hopefully we can make it work for everyone

1 Like

Hi, Thanks for sharing your experience. Actually, I was able to send http request from frontend using jquery, and I was able to get the users’ info. I’m not sure if I need backend at all for the rest of my extension. But I would be happy to share our findings to move forwards.