Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Created May 22, 2018 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphicbeacon/cb8c871e973ce8a4c4128d27fd427ef8 to your computer and use it in GitHub Desktop.
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)
@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