Categorygithub.com/chnm/apiary
modulepackage
0.0.0-20241004133023-6bd75ae353ee
Repository: https://github.com/chnm/apiary.git
Documentation: pkg.go.dev

# README

Apiary: The RRCHNM Data API

This repository provides an API to access data stored in a PostgreSQL database. It is a component of American Religious Ecologies, America's Public Bible, Death by Numbers and other projects at the Roy Rosenzweig Center for History and New Media. The API is intended for use by RRCHNM projects and is not general purpose, but we provide the source code in case it is useful. You can read more about the rationale for this piece of RRCHNM's infrastructure on our website.

Documentation

Documentation for the various endpoints and parameters to them can be found on the Go package website. Handlers are all methods on the main server type, so you can find any endpoint specific documentation on that type.

Note that the root of the API lists out all the endpoints and sample URLs, and may be more useful than the documentation for understanding how to use the API.

Configuration

Set the following environment variables to configure the server:

  • APIARY_DB (default: none). A connection string to the database. An example connection string looks like this: postgres://username:password@host:portnum/databasename.
  • APIARY_INTERFACE (default: 0.0.0.0). The interface to serve the API on.
  • APIARY_PORT (default: 8090). The port to serve the API on.
  • APIARY_LOGGING (default: on). If logging is on, then access logs will be written to stdout in the Apache Common Log format. Errors and status messages will always be written to stderr.

Compiling or running a container

There is a Makefile in the root of the repository that can be used for compiling and for running the service locally.

  • make build will build the binary.
  • make install will build the binary and install it under the name apiary to your $GOPATH.
  • make serve will serve the API locally.
  • make docker-build will create a Docker container for the API.
  • make docker-serve will create the container and run it locally via Docker.
  • make serve-ghcr. If you just need to run the Data API locally, it may be most convenient to just run a Docker container served from the GitHub Container Registry. There are versions that are tagged with each of the GitHub branches that have been pushed, so that you can try the development version from your current branch. You still need to set the environment variables.

Testing

You can run make test to run integration tests with the database. Or run go test -v ./... to get more verbose tests.

# Packages

No description provided by the author
No description provided by the author

# Functions

NewServer creates a new Server and connects to the database or fails trying.

# Structs

APBIndexItem is an entry in one of the different indexes to verses.
APBIndexItemText is an entry in one of the different indexes to verses, with the reference and the text of the verse.
APBIndexItemWithYear is an index item with the peak year.
No description provided by the author
BibleBook describes a book of the Bible and which part of the Bible it is in.
BibleSimilarityEdge describes an edge between two parts of the Bible.
CatholicDiocese describes a diocese of the Roman Catholic Church.
CatholicDiocesesPerDecade shows how many dioceses were established in North America per year.
Causes describes a cause of death.
Christenings describes a christening location.
ChristeningsByYear describes a christening's description, total count, week number, week ID, and year.
CityMembership gives the membership (and population) statistics for some aggregation of denominations in a given year.
The Config type stores configuration which is read from environment variables.
DeathCauses returns a list of causes of death with a count of deaths for each cause and related metadata.
No description provided by the author
Denomination describes a denomination's names and various systems of classification.
DenominationFamily describes a group of denominations.
Endpoint describes an endpoint available in this API and provides a sample path.
ExampleURL provides an example URL to a different way of querying the API for any given endpoint.
NullInt64 embeds the sql.NullInt64 type, so that it can be extended to change the JSON marshaling.
NullString embeds the sql.NullString type, so that it can be extended to change the JSON marshaling.
Parish describes a parish name, canonical name, and unique ID.
ParishByYear describes a parish's canoncial name, count type, total count, start day, start month, end day, end month, year, week number, and week ID.
Place represents a place with ID and name.
PlaceCounty represents a county with ID and name.
PlaceDetails represents details about a place.
PresbyteriansByYear holds aggregate data on Presbyterian membership and churches.
The Server type shares access to the database.
TotalBills returns to the total number of records in the database.
Verse describes the reference and text of a single Bible verse.
VerseQuotation is a single instance of a quotation.
VerseTrend is the rate of quotations in a single year for a single verse in a given corpus.
VerseTrendResponse wraps the data with the queries that were made.