catapult icon indicating copy to clipboard operation
catapult copied to clipboard

Provide a way to load JSON data for the server

Open mulderp opened this issue 11 years ago • 4 comments

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 avatar May 18 '13 21:05 mulderp

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

mulderp avatar May 18 '13 22:05 mulderp

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

lucasmazza avatar May 18 '13 23:05 lucasmazza

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 avatar May 19 '13 07:05 mulderp

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

mulderp avatar May 19 '13 07:05 mulderp