Created
May 16, 2018 22:38
-
-
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)
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
// 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