Chronicling America

Chronicling America

News

Provides access to millions of pages of historic US newspapers from the Library of Congress. Search the newspaper directory and digitized page contents using OpenSearch. Auto Suggest API for looking up newspaper titles Link using our stable URL pattern for Chronicling America resources. JSON views of Chronicling America resources. Linked Data views of Chronicling American resources. Bulk Data for research and external services. CORS and JSONP support for your JavaScript applications.

Visit API

📚 Documentation & Examples

Everything you need to integrate with Chronicling America

🚀 Quick Start Examples

Chronicling America Javascript Examplejavascript
// Chronicling America API Example
const response = await fetch('http://chroniclingamerica.loc.gov/about/api/', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

Using the Chronicling America API in JavaScript

If you're looking to explore the vast collection of historical newspapers on Chronicling America, you can do so using their public API. In this blog post, we'll demonstrate how to use the Chronicling America API in JavaScript, with example code snippets.

Getting Started

Before you can start making API requests, you'll need to register for an API key. Head to the Chronicling America API registration page to get started.

Once you have your API key, you're ready to start making requests.

Example 1: Searching for Newspapers

Let's say you want to search for all newspapers in the Chronicling America collection that mention the word "suffrage". Here's how you can do that in JavaScript:

const apiKey = 'YOUR_API_KEY';
const searchTerm = 'suffrage';
const url = `https://chroniclingamerica.loc.gov/search/titles/results/?terms=${searchTerm}&format=json&api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));

In this example, we're using the fetch method to make a GET request to the Chronicling America API. We pass in the API key and the search term as query parameters in the URL, and set the response format to JSON. We then parse the response using the .json() method, and log the resulting data to the console.

Example 2: Retrieving Newspaper Pages

Let's say you want to retrieve a specific newspaper page from the Chronicling America collection. Here's an example code snippet that shows you how to do that in JavaScript:

const apiKey = 'YOUR_API_KEY';
const pageUrl = 'https://chroniclingamerica.loc.gov/lccn/sn83045462/1910-01-10/ed-1/seq-1.json';
const url = `${pageUrl}?format=json&api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));

In this example, we're using the fetch method again to make a GET request to the Chronicling America API. We pass in the API key and the URL of the specific newspaper page we want to retrieve as query parameters in the URL, and set the response format to JSON. We then parse the response using the .json() method, and log the resulting data to the console.

Example 3: Retrieving OCR Text

Finally, let's say you want to retrieve the OCR text for a specific newspaper page from the Chronicling America collection. Here's an example JavaScript code snippet that shows you how to do that:

const apiKey = 'YOUR_API_KEY';
const pageUrl = 'https://chroniclingamerica.loc.gov/lccn/sn83045462/1910-01-10/ed-1/seq-1.json';
const ocrUrl = `${pageUrl}/ocr.json`;
const url = `${ocrUrl}?api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));

In this example, we're once again using the fetch method to make a GET request to the Chronicling America API. We pass in the API key and the OCR URL of the specific newspaper page we want to retrieve as query parameters in the URL. We then parse the response using the .json() method, and log the resulting data to the console.

Wrapping Up

In this blog post, we've shown you how to use the Chronicling America API in JavaScript, with example code snippets for newspaper search, newspaper page retrieval, and OCR text retrieval. Hopefully, this has given you a good starting point for exploring the vast collection of historical newspapers on Chronicling America using their public API.

📊 30-Day Uptime History

Daily uptime tracking showing online vs offline minutes

Jun 5Jun 7Jun 9Jun 11Jun 13Jun 15Jun 17Jun 19Jun 21Jun 23Jun 25Jun 27Jun 29Jul 1Jul 404008001440Minutes
Online
Offline

Related APIs in News