Hello everyone, I come to you in dire need. I am taking a code test for a job and they have given me a very strange question.
I need to request information from a database, however I cannot add anything to the testing environment.
It tells me to get HTTP GET however both HTTP and GET throw errors.
I cannot add fetch, new XMLhttprequest also is undefined.
I’m not asking for help to solve the wholeproblem, I am just stuck on this roadblock.
How do I request info from an api without any of the techniques that I’ve even heard of?
What do they want me to use?
Please help, I have been at it for 2 hours and gotten absolutely nowhere.
This is all the code that was given to me.
async function getUserTransaction(uid, txnType, monthYear) {
}
I have no code so far. I’m stuck on just the api request.
The only constraint is I can’t add anything. I’ve tried fetch, get, etc. All return undefined .
Is it me or the test?
Sorry i’d like to give you a more clear picture. Their website makes it harder for me because they prevent copy and pasting
here’s the code they give me. The fetch() part is mine and returns undefined.
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'getUserTransaction' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts following parameters:
* 1. INTEGER uid
* 2. STRING txnType
* 3. STRING monthYear
*
* https://jsonmock.hackerrank.com/api/transactions/search?txnType=
*/
async function getUserTransaction(uid, txnType, monthYear) {
fetch('https://jsonmock.hackerrank.com/api/transactions/search?txnType=')
};
Thanks for the help. I’m still getting the error, I think this code test might be a little over my head. I really appreciate you taking the time out of your day to help me though.
How would you make another request inside this one?
For example, to manipulate the information, I have to write my loops and/or if-statements, inside res.on(“end”, ( ) => { });
But with the example given for the challenge, you have to get a response first to know how many pages you have to look through. Then you have to make another GET request to get all transactions from all pages on the API.
I was wondering how you would do that.