Connor Smyth

a screenshot of a cell phone

Trivia API

A publicly available trivia API created with Laravel and PHP web scraping. The API is based on jService.io. With a total of 96,221 questions I plan on creating various applications to leverage this API in the future. Try it yourself now!

See The Project Here

I started creating this trivia API when I decided to create a trivia slack app. At first I was leveraging a different API that contained only user-submitted questions. The issue I found with it was it had only the option for true or false questions or multiple choice. I wanted something that was more of along the lines of a single question and a single answer. I didn’t want the question not to work without the other multiple-choice options.

I began looking around for a different trivia API and came across jService.io, a ruby based trivia API with 156,800 questions built by scraping jArchive. After poking around a little I discovered that it was being hosted on a simple Heroku server with many outdated Ruby dependencies. I attempted to replicate the Ruby environment on my local machine and a simple Linode server with no success, even with rvm. I noticed the developer hasn’t had much of an online presence in the last 5 years so after attempting to reach out with and receiving no response I decided to create my own trivia API.

Upon noticing that jService kept track of questions marked as invalid and also had many questions with empty questions or answers fields. I built a quick PHP script and began scraping away. I then created another PHP script after evaluating the state of the database and cleaned up the invalid questions and sent it to a developer/mentor friend who was curious, Jordana Harrison. They helped me do some further cleaning and created a new table that handled the relationships between the category names and the category IDs.

Then I started to create the API with Laravel. I am a big fan of the open-source movement so I didn’t want to bog people down with having to use API keys, similar to the way jService works. The API is free and open to the public.