Creates a static API from a CSV file and publishes it to a static web server using Travis CI. Inspired by @waldoj's instant-api.
Animals.csv
Name, Animal, Color
Fido, Dog, Brown
Whiskers, Cat, Black
Mini, Elephant, Grey
becomes
/animals.json
[
{"Name": "Fido", "Animal": "Dog", ...},
{"Name": "Whiskers", ...}
...
]
/animals/fido.json
{"Name": "Fido", "Animal": "Dog", ...}
/animals/whiskers.json
{"Name": "Whiskers", ...}
The example file in this repository, sample_data.csv, is automatically published to the gh-pages branch by Travis CI and can thus be viewed at timwis.github.io/static-api/sample-data.json, /sample-data/23.json, etc..
- Clone this repository
- run
bundle install
to install dependencies - Execute via command line using an environment variable
PRIMARY_KEY=<key> ruby static-api.rb
- Fork this repository
- Enable Travis CI integration for your fork on the travis dashboard
- Generate a new GitHub personal access token (with
public_repo
access) - On the Travis CI settings page for your fork (travis-ci.org/your-username/static-api/settings),
add your new personal access token as an environment variable with the name
GITHUB_TOKEN
. Do not enable the "Display value in build log" toggle (it's disabled by default). - Add another environment variable called
PRIMARY_KEY
set to the field name to use as the CSV file's primary key. - Add your
.csv
file to your fork by drag-and-dropping, using prose.io's CSV editor, or using traiditional git and push your changes to themaster
branch (default).
Travis CI will be triggered by a push to the master
branch, build your Static API, and push it
to the gh-pages
branch, allowing you to view it at username.github.io/repo-name/file_name.json
Hey, do you have thoughts on a better way to use this? Join the conversation!