Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Last active May 16, 2018 21:58
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/c931aa3efe007d001b7b1bf250667be3 to your computer and use it in GitHub Desktop.
Save graphicbeacon/c931aa3efe007d001b7b1bf250667be3 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 (3)
import '../fave_reads.dart';
class BooksController extends HTTPController {
// invoked for GET /books
@httpGet // HTTPMethod meta data
Future<Response> getAllBooks() async => new Response.ok('Showing all books');
// invoked for GET /books/:index
@httpGet // HTTPMethod meta data
Future<Response> getBook(@HTTPPath("index") int idx) async => new Response.ok('Showing single book');
// invoked for POST /books
@httpPost // HTTPMethod meta data
Future<Response> addBook() async => new Response.ok('Added a book');
// invoked for PUT /books
@httpPut // HTTPMethod meta data
Future<Response> updateBook() async => new Response.ok('Updated a book');
// invoked for DELETE /books
@httpDelete // HTTPMethod meta data
Future<Response> deleteBook() async => new Response.ok('Deleted a book');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment