Created
May 22, 2018 20:35
-
-
Save graphicbeacon/cb8c871e973ce8a4c4128d27fd427ef8 to your computer and use it in GitHub Desktop.
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 3)" post on Medium (4)
This file contains 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
@httpGet | |
Future<Response> getBook(@HTTPPath("index") int idx) async { | |
var query = new Query<Book>()..where.id = whereEqualTo(idx); | |
var book = await query.fetchOne(); | |
if (book == null) { | |
return new Response.notFound(body: 'Book does not exist') | |
..contentType = ContentType.TEXT; | |
} | |
return new Response.ok(book); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment