1 HTTP Request
Namhyeon, Go edited this page 2022-03-04 12:00:35 +09:00

HTTP Request

POST request with headers

var HTTP = require("lib/http");

var credential = {
    "email": document.getElementById("txt_email").value,
    "password": document.getElementById("txt_password").value
};

HTTP.create()
    .setContentType("application/json")
    .setRequestBody(credential)
    .post(apiUrl + "myproject/auth/authenticate", function(res) {
        if ("error" in res) {
            console.error(res.error.message);
        } else if ("data" in res) {
            console.log(res.name);
        }
    })
;

GET request with headers

var HTTP = require("lib/http");

HTTP.create()
    .setContentType("application/x-www-form-urlencoded")
    .setBearerAuth(token)
    .setUseCache(false)
    .get(apiUrl + "myproject/items/mycollection", function(res) {
        if ("error" in res) {
            console.error(res.error.message);
        } else if ("data" in res) {
            console.log(res.name);
        }
    })
;