How to Get Public Holiday Information (100+ Countries) using JavaScript

If you’re adding basic date & time services to your app, you might benefit from this one: Our Public Holiday API quickly provides public holiday records in more than 100 countries, including specific data about when the holiday occurs, whether it’s a nationwide holiday, what the local name for the holiday is (all information is provided in English by default), and more. It requires the raw country & year as input in order to access the appropriate records.

You can easily take advantage of this API with a free Cloudmersive account & API key by structuring your API call with the JavaScript code examples provided below.

To structure your call using the XHR feature in JavaScript, use the following snippet:

var data = JSON.stringify({
"RawCountryInput": "<string>",
"Year": "<integer>"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.cloudmersive.com/validate/date-time/get/holidays");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Apikey", "YOUR-API-KEY-HERE");
xhr.send(data);

To install jQuery instead, run the below command:

bower install jquery

And then call the API:

var settings = {
"url": "https://api.cloudmersive.com/validate/date-time/get/holidays",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": JSON.stringify({
"RawCountryInput": "<string>",
"Year": "<integer>"
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});

All done — no further code contributions required!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.