byu-api-request
Utility for making a server to server request using BYU's current API gateway authentication method
Requires Node 18+
Installation
npm i --save byu-api-request
Usage
This package will automatically generate the host domain to be used based on your environment variables.
You need to have a variable named ENVIRONMENT_NAME in you environment variables and have it assigned to one of the following values:
prd
for Productiondev
for Sandboxapidev
for API Development
Set up with setOauthSettings
and then make requests with request
, using only the
Examples:
const api = require('byu-api-request')
(async () => {
await api.setOauthSettings('myClientKey', 'myClientSecret')
try {
const response1 = await api.request({ url: `/echo/v1/echo/test` })
const response2 = await api.request({ method: 'PUT', url: `/byuapi/students/v2/123456789/enrolled_classes/Summer2019,BIO,100,001`, body: { credit_hours: 3 } })
const response3 = await api.request({ url: `/echo/v1/echo/test` }, 'some original jwt to pass along')
const response4 = await api.request({ url: `/echo/v1/echo/test`, simple: false, resolveWithFullResponse: true })
} catch (e) {
console.error(e)
}
})
For more information on the options you can use for the request
function, see fetch.