API Documentation
Start with the API Documentation and then experiment with the examples below.
Code Examples
Website administrators can use these APIs on either the front-end or back-end to embed the daily readings on the sites they maintain. Following are some simple examples of how to fetch the data from the api and incorporate it into a page using either PHP or Javascript.
PHP Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get today's information | |
$json = file_get_contents('https://orthocal.info/api/gregorian/'); | |
$day = json_decode($json); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Daily Readings</title> | |
</head> | |
<body> | |
<h1><?= $day->summary_title ?></h1> | |
<h2>Scripture Readings</h2> | |
<?php foreach ($day->readings as $reading): ?> | |
<h3><?= $reading->display ?></h3> | |
<?php foreach ($reading->passage as $verse): ?> | |
<p> | |
<sup><?= $verse->verse ?></sup> | |
<?= $verse->content ?> | |
</p> | |
<?php endforeach; ?> | |
<?php endforeach; ?> | |
<h2>Commemorations</h2> | |
<?php foreach ($day->stories as $story): ?> | |
<h3><?= $story->title ?></h3> | |
<?= $story->story ?> | |
<?php endforeach; ?> | |
</body> | |
</html> |
Browser-based Javascript Examples
HTML With jQuery Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<h1 id="title"></h1> | |
<p id="fast"></p> | |
<p id="readings"></p> | |
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$.ajax('https://orthocal.info/api/gregorian/').done(function (data) { | |
$('#title').text(data.summary_title); | |
$('#fast').text(data.fast_level_desc + ' — ' + data.fast_exception_desc); | |
$('#readings').text(data.readings.map(r => r.display).join('; ')) | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
ES6 Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<h1>Daily Readings</h1> | |
<article id="readings"> | |
</article> | |
</body> | |
<script> | |
async function load_readings() { | |
// Use the client's date since the server is always set to Pacific Timezone | |
const today = new Date() | |
// JS months are zero-origin, so we have to add 1 to the month | |
const url = `https://orthocal.info/api/gregorian/${today.getFullYear()}/${today.getMonth()+1}/${today.getDate()}/` | |
const response = await fetch(url) | |
if (response.ok) { | |
const day = await response.json() | |
// Get an abbreviated subset of the readings | |
abbr_readings = day.abbreviated_reading_indices.map(index => day.readings[index]) | |
// Use a string template to generate new HTML and add it to the | |
// readings article in the markup. | |
document.querySelector('#readings').innerHTML = ` | |
<h2>${today.toDateString()}</h2> | |
<h3>${day.summary_title}</h3> | |
<h2>Scripture Readings</h2> | |
${abbr_readings.map(reading => ` | |
<h3>${reading.display}</h3> | |
<!-- There is no markup in the verses, so we wrap the whole thing in <p> tags --> | |
<p>${reading.passage.map(verse => verse.content).join(' ')}</p> | |
`).join('')} | |
<h2>Commemorations</h2> | |
${day.stories.map(story => ` | |
<h3>${story.title}</h3> | |
<!-- Stories already have the html markup embedded, so we don't need <p> tags --> | |
${story.story} | |
`).join('')} | |
` | |
} | |
} | |
document.addEventListener('DOMContentLoaded', load_readings) | |
</script> | |
</html> |
React.js Example
You can view the code for the previous version of this site that was built with React.js in the orthocal-client Github repository.