Created
June 14, 2014 17:19
-
-
Save kblake/adf2d037a60804004a12 to your computer and use it in GitHub Desktop.
What if... Swinatra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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