Skip to content

Instantly share code, notes, and snippets.

@prochor666
Last active July 13, 2018 10:23
Show Gist options
  • Save prochor666/59fb6c407caaa32ca37fde810aed186d to your computer and use it in GitHub Desktop.
Save prochor666/59fb6c407caaa32ca37fde810aed186d to your computer and use it in GitHub Desktop.
api.heimdaldata.dk

Request badge pdf with api.heimdaldata.dk

Send a POST to url: http://api.heimdaldata.dk/badge/

With following POST dataset:

header: "#hashtag",
image: "image-blob",
title: "Queen",
name: "Daenerys Targaryen",
assignment: "Crew",
access: "All areas",
textColor: "#000000", // optional, default #000000
backgroundColor: "#FFFFFF", // optional, default #FFFFFF

API response

Example JSON response:

{
    "status": true,
    "reason": "Job finished for badge-daenerys-targaryen",
    "pdf": "http://api.heimdaldata.dk/badge/storage/pdf/badge-daenerys-targaryen.pdf?_=ha7YEi7wCChLXpbi0wcClPK52AWXMU22"
}

Parse JSON response with your prefered language

Javascript jQuery example code.

AJAX request & response:

$.ajax({
    type: 'POST',
    url: 'http://api.heimdaldata.dk/badge/',
    dataType: "json",
    data: {
        header: "#hashtag",
        image: "image-blob",
        title: "Queen",
        name: "Daenerys Targaryen",
        assignment: "Crew",
        access: "All areas",
    },
    async: true,
    cache: false,
    error: function(jqXHR, textStatus, errorThrown){
        // Parse error output here
        console.log(jqXHR, textStatus, errorThrown);
    },
    success: function(response){
        // Parse valid JSON output here
        consolelog(response);
    },
});

Vanila Javascript example code.

AJAX request & response:

var data = data: {
    header: "#hashtag",
    image: "image-blob",
    title: "Queen",
    name: "Daenerys Targaryen",
    assignment: "Crew",
    access: "All areas",
};
var xhr = new XMLHttpRequest();
//Send the proper header information along with the request
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

//Call a function when the state changes.
xhr.onreadystatechange = function() {
    if(this.readyState == XMLHttpRequest.DONE && this.status == 200) {
        // Parse valid JSON output here
        console.log(JSON.parse(this.responseText));  
    }else{
        // Parse error output here
        console.log(this.statusText);
    }
}

xhr.open("POST", 'http://api.heimdaldata.dk/badge/', true);
xhr.send(JSON.stringify(data)); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment