catapult
catapult copied to clipboard
Provide a way to load JSON data for the server
The idea of this PR is a way to get JSON into the browser. This might be interesting when designing views for data that is loaded with Ajax, e.g some movies collection.
By putting a file ./data/movies.json with content:
[{ "title": "Midnight in Paris" }]
it is possible to load the JSON from the browser with e.g.:
$.get("/movies.json", function(data) { console.log(JSON.parse(data)); })
results into
[ { title: 'Midnight in Paris' }]
Underlying this is Sinatra reading all .json files from the ./data directory.
What do you think?
Additionally, some interesting variation might be include Redis or some store to load data from a DB, instead of files.
Isn't easier to place your file inside public
and let the Static server serve it? (I guess it should work)
Thanks, indeed, placing the JSON in the public works too. The approach with Sinatra then only would make sense, when a resources/files would be created, or a database would be involved.
Well, some of the original idea was to have some way to get started with API development in Ruby too. A similar approach to: http://www.arangodb.org/foxx and more ideas on API co-development here: http://www.arangodb.org/2013/05/14/ideas-and-facts-from-scotland-js-in-edinburgh