@mome0320/kartrider.js-fetch
Version:
KartRider library interacting with Nexon API use fetch
28 lines (27 loc) • 1.34 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchFromAPI = void 0;
require("cross-fetch/polyfill");
const baseURL = 'https://api.nexon.co.kr/kart/v1.0/';
const fetchFromAPI = (urlPath, URLInfo) => __awaiter(void 0, void 0, void 0, function* () {
let url = baseURL + urlPath;
if (URLInfo.params)
url += "?" + URLInfo.params.toString();
const fetchResult = yield fetch(url.toString(), {
method: URLInfo.HTTPMethod || "GET",
headers: {
'Authorization': URLInfo.token,
}
}).then(res => res.json());
return fetchResult;
});
exports.fetchFromAPI = fetchFromAPI;