Skip to content

Instantly share code, notes, and snippets.

@kblake
Created June 14, 2014 17:19
Show Gist options
  • Save kblake/adf2d037a60804004a12 to your computer and use it in GitHub Desktop.
Save kblake/adf2d037a60804004a12 to your computer and use it in GitHub Desktop.
What if... Swinatra
get ("/movies") {
return Movie.all
}
get ("/movies/:id") {
movie = Movie.get(params["id"])
return movie
}
post ("/movies") {
body = JSON.parse(request.body.read)
movie = Movie.create(
title: body["title"],
director: body["director"],
synopsis: body["synopsis"],
year: body["year"]
)
return movie, "201"
}
put ("/movies/:id") {
body = JSON.parse(request.body.read)
movie = Movie.get(params["id"])
movie.update(
title: body["title"],
director: body["director"],
synopsis: body["synopsis"],
year: body["year"]
)
return movie
}
delete ("/movies/:id") {
movie = Movie.get(params["id"])
movie.destroy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment