jlong / serve

Serve is a small Rack-based web server and rapid prototyping framework for Web applications (specifically Rails apps). Serve is meant to be a lightweight version of the Views part of the Rails MVC. This makes Serve an ideal framework for prototyping Rails applications or creating simple websites. Serve has full support for Rails-style partials and layouts.
http://get-serve.com
Other
836 stars 90 forks source link

Add a JSON handler to serve dynamic data #34

Closed datenimperator closed 13 years ago

datenimperator commented 13 years ago

To test dynamic components serve needs to properly handle responses in json format. The patch adds a file handler that will serve files with extension .json as such, and parse YAML files .yml to send the results as json, too.

jlong commented 13 years ago

Did I reply on this? I'm on board with this, just not sure about delivering YAML as JSON. Can we back out of that?

jlong commented 13 years ago

Also, we should update the "test_project" with a few test files.

datenimperator commented 13 years ago

Hm, my email reply didn't get to here? I wasn't sure about YAML, either. However, YAML mixins allow to build bigger data structures more easily, so I figured it might be a good idea.

---
base: &base
  occupation: 'Thief'
  weapon: 'Revolver'
data:
- firstname: 'Joe'
  lastname: 'Dalton'
  <<: *base
- firstname: 'Averell'
  lastname: 'Dalton'
  <<: *base

which gives us a data structure of

{
  "base": {
    "weapon": "Revolver", 
    "occupation": "Thief"
  }, 
  "data": [
    {
      "firstname": "Joe", 
      "lastname": "Dalton", 
      "weapon": "Revolver", 
      "occupation": "Thief"
    }, 
    {
      "firstname": "Averell", 
      "lastname": "Dalton", 
      "weapon": "Revolver", 
      "occupation": "Thief"
    }
  ]
}
jlong commented 13 years ago

Yeah, I can see the advantage.

Perhaps the extensions for YAML/JSON parsing should be .json.yml and .json.yaml. I don't want to override regular YAML files just for this.

If you will rebase on jlong/master, add some test files to test_project, and fix the extension issue for YAML, I'll merge.