Chronicling America

Chronicling America

  • Category: News


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.

Visit to Chronicling America website

Similar APIs of News

Contify

Contify

News

Enrich your apps with machine-readable and properly structured news feeds with the help of Contify. It tags, duplicates, and aggregates data and delivers through RSS feeds, webhooks, and RESTful APIs. Contify offers wide coverage of clean and company-based intelligence data relevant to specific business or industry, instead of keyword-based feeds. It collects data from 200k+ sources, including company websites, online news, social media, reviews websites, regulatory portals, job boards, niche and premium publications. In addition to that, it allows you to integrate your preferred sources for fetching user-relevant data from anywhere across the globe. Contify also provides multi-language support through SmartTranslate so that you can source intel from publications in 100s of languages. They combine AI and machine-learning technologies with human intelligence to deliver deduplicated and actionable data feed, identify trends, and maintain system integrity. The platform also includes noise-filtering algorithms like NLP, NER, and disambiguation, to ensure a constant flow of quality updates. With API endpoints and customized taxonomy, they structure all the sourced data with their endpoints to align your business goals. Enjoy frictionless collaboration using a fully dedicated account management.

machinereadablestructured

Connexun

Connexun

News

Search news content in real-time by taking advantage of the sophisticated technology of Connexun that crawls and indexes thousands of sources every day. Analysing the published content becomes easy with their live dataset containing cleaned-up news feeds. It allows you to discover trending global news that their unique algorithms evaluate. You can also filter news by selecting the language of your choice and news items. Select two countries of your interest and access all the latest news from them using their InterCountry API. Similarly, you can discover popular news from the media outlets of a selected country or news from a country frequently mentioned by global news sources. There’s one more fascinating feature of Connexun – it lets you access news from a particular place using its longitude and latitude. With its powerful search engine, Connexun API can display the textual news content related to a keyword or topic and is acquired from 1 million pages each month.

newssearchengine

Contextual Web

Contextual Web

News

Search from 100k news sources to find news feeds, posts, articles, and blogs on the topic of your choice using ContextualWeb. By integrating with RapidAPI, you can obtain your API key and make a GET request within seconds. ContexualWeb has one of the most advanced search algorithms on the internet, which helps you find what you are looking for precisely and fast. They respect your privacy by employing the highest privacy protection; hence, your search history or data is never available to someone else.

feedspostsarticles

Spaceflight News

Spaceflight News

News

Get an overview of the latest Spaceflight news, Articles, Reports from various sources! Easily link your users to the right websites

spaceflightnews

News Catcher API

News Catcher API

News

News API to find news articles by any topic country language website or keyword

newscatcherapi

Hubblesite

Hubblesite

News

Space Telescope News Releases

Spacetelescopenews

News API

News API

News

Get breaking news headlines, and search for articles from over 30,000 news sources and blogs with our news API. Freaking fast because everything is asynchronously cached for a super-fast response. Free for development and easy integration.

Fastnewsblogs

Currents

Currents

News

Currents - Capture the world news through simple json news API. Latest news published in various news sources, blogs and forums. 26 Million Entries and Counting, 18 Languages, News API sourced from over 70 countries, Data from Over 17,000 sources, 70,000 articles added daily and access to historical data.

Historyheadlinesdata

The Old Reader

The Old Reader

News

We have implemented a GoogleReader-like mobile API that allows anyone to create a mobile app that works with The Old Reader. You can add websites to your reading lists, organise your interests, and share to connect with friends.

readerbookadd

NPR One

NPR One

News

Personalised news LISTENING experience from NPR. Get listings according to available channels, organisations, recommendations, ratings, history, aggregation and make search queries.

audiolistenchannels