3.3.3 • Published 2 years ago

byu-wso2-request v3.3.3

Weekly downloads
678
License
Apache-2.0
Repository
github
Last release
2 years ago

BYU logo byu-wso2-request

Utility for making a server to server request using wso2 authentication

codecov

Requires Node 10+

Installation

npm i --save byu-wso2-request

Migration from v1 to v2.1+

  • Update to Node 8 or above
  • Use promises instead of callbacks for request

Migration from v2 to v3

  • Update to Node 10 or above
  • If you want the statusCode property added to responses, make the requests with the resolveWithFullResponse option set to true (See: #30)

Usage

Set up with setOauthSettings and then make requests with request

Examples:

const wso2 = require('byu-wso2-request')

(async () => {
  // Will default to api.byu.edu if host is not passed in
  const production = process.env.ENVIRONMENT_NAME === 'prd'
  const host = production ? 'api.byu.edu' : 'api-sandbox.byu.edu'
  
  // Alternatively, you can set the host in the environment variables
  // process.env.WSO2_HOST = 'api.byu.edu'

  // Do this once on startup
  await wso2.setOauthSettings('myClientKey', 'myClientSecret', { host })
  
  // After that, make all the requests you want
  try {
    // Simple GET request
    const response1 = await wso2.request({ url: `https://${host}/echo/v1/echo/test` })

    // Request using another method
    const response2 = await wso2.request({ method: 'PUT', url: `https://${host}/byuapi/students/v2/123456789/enrolled_classes/Summer2019,BIO,100,001`, body: { credit_hours: 3 } })
    
    // Request that passes along an original JWT
    const response3 = await wso2.request({ url: `https://${host}/echo/v1/echo/test` }, 'some original jwt to pass along')
    
    // Request where you want to know what status code came back (instead of just rejecting if it's not 2XX)
    const response4 = await wso2.request({ url: `https://${host}/echo/v1/echo/test`, simple: false, resolveWithFullResponse: true })
  } catch (e) {
    console.error(e) // Handle errors
  }
})

For more information on the options you can use for the request function, see request-promise

3.3.1

2 years ago

3.3.3

2 years ago

3.3.2

2 years ago

3.2.2-1

2 years ago

3.2.2-0

2 years ago

3.3.0

2 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.1.0

4 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.2.1

4 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

7 years ago