Skip to content

Instantly share code, notes, and snippets.

@hmaurer
Created August 21, 2012 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hmaurer/3418198 to your computer and use it in GitHub Desktop.
Save hmaurer/3418198 to your computer and use it in GitHub Desktop.
Foo = {}
Foo.DataSource = {}
class Foo.DataSource.REST
(baseUrl) ->
@baseUrl = baseUrl
fetchAll: !->
@doRequest("GET", @baseUrl, {
success: (data, event, response) ->
console.debug data
})
fetch: !(id) ->
@doRequest("GET", this.baseUrl + "/" + id)
create: !(data) ->
@doRequest("POST", this.baseUrl, {data: data})
update: !(id, data) ->
@doRequest("PUT", this.baseUrl + "/" + id, {data: data})
delete: !(id) ->
@doRequest("DELETE", this.baseUrl + "/" + id)
doRequest: (method, url, options) ->
$.ajax({
type: method,
url: url
} <<< options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment