Skip to content
An API for the classic fortune command-line utility (in the fortune-mod package)
Go CMake
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
datfiles
pkg/linux_amd64/github.com/gorilla Fix dependencies Nov 25, 2018
src/github.com Fix dependencies Nov 25, 2018
vendor Change router for Heroku deployment Nov 25, 2018
LICENSE
Procfile.txt
README.md
fortune-api Fix dependencies Nov 25, 2018
main.go

README.md

🔮 fortune-api 🔮

forthebadge

Codacy Badge Go Report Card

Description

A RESTful API for the classic fortune command-line utility (in the fortune-mod package). Every query will return a random fortune! These fortunes are originally from the fortune-mod repository, from the original command line utility.

It is hosted at fortuneapi.heroku.com.

Adding Fortunes

To add a new fortune, go to the datfiles directory, and choose the correspoding file to contribute to. If none of the files fit, feel free to make your own! As with the original, fortunes deemed to be not-so-wholesome should be confined to the datfiles/off directory.

Simply type your fortune, formatted as you wish, and then follow it with a newline containing a %. That's all!

Running Locally

To run the API locally, ensure that you have Go 1.7+ installed.

The only dependency needed is mux, which can be installed by running:

$ go get github.com/gorilla/mux

In the repository folder, use the following to run the API server:

$ go run main.go

The API is hosted at fortuneapi.heroku.com, but you can change this in the main() function in the main.go file to run it locally.

I recommend changing it as follows:

Replace these lines in main():

	port := ":" + os.Getenv("PORT")
	log.Fatal(http.ListenAndServe(port, router))

With this line:

    log.Fatal(http.ListenAndServe(":8080", router))

Now you can access the API at localhost:8080!

Endpoints

No additional path is needed if you would like a completely random fortune.

You can get a fortune from a specific genre at fortuneapi.heroku.com/<genre>, replacing 'genre' with the desired datfile name. The genre must be the exact name of one of the files in the datfiles directory. For example, fortuneapi.heroku.com/computers could give you an output such as:

"We are experiencing system trouble -- do not adjust your terminal.\n"

Note: the output is always random, so even with the same URL, the output will likely vary with every query

You can’t perform that action at this time.