API Atlas

API Atlas is an example of distant API provided with NodeAtlas.

See code source this page here.

API's List

Call Example from External Projects

Client Side - with Vanilla JS

`GET http://www.lesieur.name/api/comments/`

Code

/* jslint browser: true */
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.lesieur.name/api/comments/", true);
xhr.addEventListener("readystatechange", function () {
    var commentsArea = document.getElementsByClassName("comments")[0],
        comments;

    if (xhr.readyState === 4 && xhr.status === 200) {
        comments = JSON.parse(xhr.responseText);
        comments.forEach(function (comment) {
            var group = document.createElement("li"),
                title = document.createElement("h4"),
                paragraph = document.createElement("p");

            title.textContent = comment.id;
            paragraph.textContent = comment.message;

            group.appendChild(title);
            group.appendChild(paragraph);
            commentsArea.appendChild(group);
        });
    }
});
xhr.send(null);

Result

Server Side - with NodeAtlas

`GET http://www.lesieur.name/api/comments/`

Code

/* jslint node: true, esversion: 6 */
exports.changeVariations = function (next, locals) {
    var NA = this,
        http = NA.modules.http,
        result = "";

    http.get({
        hostname: "www.lesieur.name",
        port: 80,
        path: "/api/comments/",
        agent: false
    }, function (response) {
        response.on("data", function (chunk) {
            JSON.parse(chunk).forEach(function (comment) {
                result += `<div>
                    <h4>
                        ${comment.id}
                    </h4>
                    <p>
                        ${comment.message}
                    </p>
                </div>`;
            });

            locals.comments = result;
            next();
        });
    }).on('error', function () {
        locals.comments = "";
        next();
    });
};

Result

  • c82c8370-ee9f-11e6-be90-17360ea14e75

    Un message

  • 0f6f6fb0-efb1-11e6-ac84-43a396bdeaf9

    Tata

  • 16feb560-efb1-11e6-ac84-43a396bdeaf9

    Ceci est un test