Functions request
and promise
are overritable
Does a POST request and returns a promise
Returns a promise
which resolves with result
Return a single record by id
User.find(15).then (user) ->
alert "Yo, #{user.name}"
Return a single record by params
User.findBy(name: 'John', city: 'New York').then (user) ->
alert "I'm John from New York"
Specify id
when updating or destroying the record.
User = new Databound '/users'
User.update(id: 15, name: 'Saint John').then (updated_user) ->
alert updated_user
User.destroy(15).then (resp) ->
alert resp.success
Just take already dowloaded records
f.e. Have default records
backend responds with:
{
success: true,
id: record.id,
scoped_records: []
}
You can specify scope for the connection.
User = new Databound '/users', city: 'New York' User.where(name: 'John').then (users) -> alert 'You are a New Yorker called John' User.create(name: 'Peter').then (new_user) -> # I am from New York alert "I am from #{new_user.city}"