🔮 fortune-api 🔮
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.
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
Simply type your fortune, formatted as you wish, and then follow it with a newline containing a
%. That's all!
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
port := ":" + os.Getenv("PORT") log.Fatal(http.ListenAndServe(port, router))
With this line:
Now you can access the API at
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
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