Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Forked from hmaurer/gist:3418198
Created August 21, 2012 18:36
Show Gist options
  • Save vendethiel/3418210 to your computer and use it in GitHub Desktop.
Save vendethiel/3418210 to your computer and use it in GitHub Desktop.
Foo = DataSource: {}
class Foo.DataSource.REST
(@baseUrl) ->
fetchAll: !->
@doRequest("GET", @baseUrl,
success: (data, event, response) ->
console.debug data
)
fetch: !(id) ->
@doRequest("GET", "#{@baseUrl}/#id")
create: !(data) ->
@doRequest("POST", @baseUrl, {data})
update: !(id, data) ->
@doRequest("PUT", "#{@baseUrl}/#id", {data})
delete: !(id) ->
@doRequest("DELETE", "#{@baseUrl}/#id")
doRequest: (type, url, options) ->
$.ajax({type, url} <<< options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment