maccman / catapult

A Sprockets/Rack build tool
MIT License
137 stars 14 forks source link

Provide a way to load JSON data for the server #14

Open mulderp opened 11 years ago

mulderp commented 11 years ago

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?

mulderp commented 11 years ago

Additionally, some interesting variation might be include Redis or some store to load data from a DB, instead of files.

lucasmazza commented 11 years ago

Isn't easier to place your file inside public and let the Static server serve it? (I guess it should work)

mulderp commented 11 years ago

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.

mulderp commented 11 years ago

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