A JS library that laughs at your four winds.
Below is our example JSON response from the RESTful API endpoint http://example.com/snakepits/1.json:
{
"depth": 40,
"units": "meters",
"owner": {
"name": "Crom",
"title": "God of Steel"
},
"snakes": [
{
"length": "20",
"units": "meters",
"isVenomous": true,
"likes": "killing the shit out of people."
},
{
"length": "12",
"units": "meters",
"isVenomous": false,
"likes": "long walks on the beach."
}
]
}And now, the corresponding Backbone Models, leveraging Crom:
classPersonextendsCrom.Modeldefaults:name:nulltitle:nullclassSnakeextendsCrom.Modeldefaults:length:0units:nullisVenomous:falselikes:nullclassSnakesextendsCrom.Collectionmodel: SnakeclassSnakepitextendsCrom.Model# our glorious RESTful endpointurl:'http://example.com/snakepits'defaults:depth:0units:null# Here we have some nested datanested:->owner: Person
snakes: SnakesNow we're able to put our models to the test:
snakepit=newSnakepit(id:1)
snakepit.fetch()
snakepit.owner# -> an instance of the Person modelsnakepit.snakes# -> an instance of the Snakes collection