В NodeJS используя библиотеку Unirest http, я автоматизирую Rest Apis. В настоящее время я застрял на том, как передать параметры запроса с остальным URL.
Я пробовал следующие решения, но не работает: решение 1
unirest('GET', 'https://my-domain.com/Api/learner/courses')
.header({
"content-type": "application/json",
"authorization": token
})
.queryString("pageNumber", "1")
.queryString("sortDirection", "ASC")
.queryString("status", "all")
.end(function (response) {
response.status.should.be.equal(200);
});
получил следующую ошибку при выполнении выше:
TypeError: unirest(...).header(...).queryString is not a function
решение 2:
unirest('GET', 'https://my-domain.com/Api/learner/courses{pageNumber}{sortDirection}{status}')
.header({
"content-type": "application/json",
"authorization": token
})
.routeParam("pageNumber", "1")
.routeParam("sortDirection", "ASC")
.routeParam("status", "all")
.end(function (response) {
response.status.should.be.equal(200);
});
получено сообщение об ошибке:
TypeError: unirest(...).header(...).routeParam is not a function
решение 3:
const param = {
pageNumber: 1,
sortDirection: "ASC",
status: "all"}
unirest ('GET') , 'https://my-domain.com/Api/learner/courses {pageNumber} {sortDirection} {status}') .header ({"content-type": "application / json", "authorization": token}) .send ( param) .end (function (response) {response.status.should.be.equal (200);});
получил ошибку:
Uncaught Error: Error: got 500 response
Любая помощь будет очень ценной ! спасибо.