Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Created May 16, 2018 22:38
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/b647e84786c40f9b1fe76b55d898a55c to your computer and use it in GitHub Desktop.
Save graphicbeacon/b647e84786c40f9b1fe76b55d898a55c to your computer and use it in GitHub Desktop.
Sample code for "Building RESTful Web APIs with Dart, Aqueduct and PostgreSQL (Part 2)" post on Medium (7)
// lib/controller/book_controller.dart
import '../fave_reads.dart';
import 'model/book.dart';
List books = [
new Book(
title: 'Head First Design Patterns',
author: 'Eric Freeman',
year: 2004
),
new Book(
title: 'Clean Code: A handbook of Agile Software Craftsmanship',
author: 'Robert C. Martin',
year: 2008
),
new Book(
title: 'Code Complete: A Practical Handbook of Software Construction',
author: 'Steve McConnell',
year: 2004
),
];
class BooksController extends HTTPController {
// ...
// ...
Future<Response> addSingle(@HTTPbody() Book book) async { // note the `Book` type being used
books.add(book);
return new Response.ok(book);
}
//...
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment