Search code examples
node.jsexpressjwtexpress-jwtrequest-promise

How to perform JWT API request on Express.js server? (edX API)


This is probably a super-easy answer for most folks, but I'm new to back-end. I'm using Express.js to implement my server, and I need to retrieve courses from the edX API. Below is the sample request they have on their docs:

curl -X GET -H "Authorization: JWT {access token}" https://api.edx.org/catalog/v1/catalogs/

and I can't seem to find a starting point on how to translate this to Express.js implementations. I was able to perform similar requests to another API using 'request-promise'), but this is the first that requires a JWT Auth...

Docs here: http://course-catalog-api-guide.readthedocs.io/en/latest/course_catalog/catalog.html#get-a-list-of-all-course-catalogs

Thanks a ton in advance!


Solution

  • Turns out it was super similar to the above, but with a different setup (using the request-promise library):

    request.get('https://api.edx.org/catalog/v1/catalogs/', {
     "url":APIURL,
     "headers":{
        "Authorization": "JWT {access token}",
        "User-Agent": "client"
      }
    });
    

    Source: Using an authorization header with Fetch in React Native