A Promised-wrapped Node library and ORM for https://scripture.api.bible/.
This includes a bibleService
which is a promised-wrapped library for the API with some convenience methods.
But it also includes an ORM that turns data into Bible
, Book
, Chapter
, Verse
, and Passage
objects that have their own convenience methods and relations for easier navigation of scripture.
- Node 12+
- NPM 6.14.12
- go to https://scripture.api.bible
- Sign up
- Go to Applications
- Create a new application
- After it's created you will need the credentials
This is thoroughly documented via JSDoc and a Github Wiki
Using the API and this library amounts to three steps:
- Create the Bible Service
- Use the Bible service to get the id for a Bible
- Do stuff with a Bible id
The Bible Id that you get is needed to get any data from the API. For this reason, there exists a whole ORM that you can use which turns books, chapters, verses, and passages into objects that let you request data when you want it.
But you can't get there until you have at least a service.
You may want multiple services if you plan on using different versions of the api, or fetching text and audio.
const {BibleService} = require('berea');
const service = new BibleService('someLongToken');
As the API itself is version controlled, the library is too. This is an optional second parameter:
const {BibleService} = require('berea');
const service = new BibleService('someLongToken', 1);
The Bible API itself offers text and audio. As you may want one over the other, this is an optional third parameter. The options are text
or audio
.
const {BibleService} = require('berea');
const service = new BibleService('someLongToken', 1, 'audio');
All of the request options are documented. One notable difference between how this library works is that options can be camelCased.
While the API will require content-type
if you want to set options, you can send contentType
.
Look in src/constants/requestParameters.js
for all of the aliases. RequestParameters
is also set as a static property on the BibleService
class.
Before getting verses, chapters, or passages, you need a bibleId
. The only way to know that is to look at all of the Bibles, first.
- Request Options ( an array)
async function doThings() {
const bibles = await service.getBibles();
}
- Response (an array)
async function doThings() {
const bibles = await service.getBibles({
language: 'eng'
});
}
- Response
- Request: only a string
Once you've found a bibleId
, you can get some information on it.
async function doThings() {
const bible = await service.getBible('06125adad2d5898a-01');
}
About bookId
:
A bookId
is typically the first 3-letters of the name of a book.
e.g.
- Exodus => EXO
- Mark => MAR
- Request Options
- Response (an array)
- A Single parameter can be passed, an object, containing
id
forbibleId
with additional options. Here, all that's passed is thebibleId
as a string.
async function doThings() {
const books = await service.getBooks('06125adad2d5898a-01');
}
- Request Options
- Response (an array)
- A Single parameter can be passed, an object, containing
id
forbibleId
with additional options.includeChapters
is an option that's passed in.
async function doThings() {
const books = await service.getBooks({
id: '06125adad2d5898a-01'
includeChapters: true,
});
}
About chapterId
:
- Take the three-letter abbrevation ( EXO)
- Add a
.
- Then add the number
e.g.
- Exodus 1 => EXO.1
- Mark 8 => MAR.8
- Request Options
- Response (an array)
- A Single parameter can be passed, an object, containing
id
forbibleId
andbookId
with additional options.
async function doThings() {
const exodusChapters = await service.getChaptersFromBook('c315fa9f71d4af3a-01', 'EXO');
}
- Request Options
- Response
- A Single parameter can be passed, an object, containing
id
forbibleId
andchapterId
with additional options.
async function doThings(){
const chapter = service.getChapter('c315fa9f71d4af3a-01', 'EXO.1');
}
About verseId
:
- Take the
chapterId
( EXO.1) - Add a
.
- Then add the number
e.g.
- Exodus 1:1 => EXO.1.1
- Mark 8:8 => MAR.8.8
- Response (as array)
Note that this will not give you the content of the verses. It may be useful, however, in getting verseId
s
async function doThings(){
const chapter = service.getVersesFromChapter('c315fa9f71d4af3a-01', 'EXO.1');
}
- Request Options
- Response
- A Single parameter can be passed, an object, containing
id
forbibleId
andverseId
with additional options.
Note that This only returns one verse, for multiples you want a passage.
async function doThings(){
const chapter = service.getVerse('c315fa9f71d4af3a-01', 'EXO.1.1');
}
Note: This is an alias for getPassage()
async function doThings(){
const chapter = service.getPassage('c315fa9f71d4af3a-01', 'EXO.1.1-EXO.1.20');
}
About verseId
:
- Take the
verseId
( EXO.1.1) - Add a
-
- Then add the
verseId
for the last verse
e.g.
- Exodus 1:1-20 => EXO.1.1-EXO.1.20
- Mark 8:8-14 => MAR.8.8-MAR.8.14
- Request Options
- Response
- A Single parameter can be passed, an object, containing
id
forbibleId
andpassageId
with additional options.
async function doThings(){
const chapter = service.getPassage('c315fa9f71d4af3a-01', 'EXO.1.1-EXO.1.20');
}