Last active
October 27, 2016 15:07
-
-
Save rjriel/b4dea7e6a229137feba02a9f557563c8 to your computer and use it in GitHub Desktop.
CREATE OPTIONS FUNCTION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the api key passed to the Qritter Wars REST API in the Authorization header | |
// for authentication | |
// format: base64 encoded value of <apiId>:<apiSecret> | |
const apiKey = new Buffer(`${config.apiId}:${config.apiSecret}`).toString('base64') | |
let createOptions = (endpoint, method, body) => { | |
// we need to return all options that the request module expects | |
// for an http request. 'uri' is the location of the request, 'method' | |
// is what http method we want to use (most likely GET or POST). headers | |
// are the http headers we want attached to our request | |
let options = { | |
uri: `http://${config.host}:${config.apiPort}/${endpoint}`, | |
method: method.toUpperCase(), | |
headers: { | |
"Authorization": `Basic ${apiKey}`, | |
"Content-Type": "application/json" | |
} | |
} | |
if (body != null) { | |
// if a body has been specified we want to add it to the http request | |
options.body = JSON.stringify(body) | |
} | |
return options | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment