Created
May 16, 2018 21:39
-
-
Save graphicbeacon/d130b47478288c7a5f476c84e5a6b030 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 (2)
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
router.route('/books[/:index]').listen((Request incomingRequest) async { | |
String reqMethod = incomingRequest.innerRequest.method; | |
String index = incomingRequest.path.variables["index"]; | |
if (reqMethod == 'GET') { | |
if(index != null) { | |
return new Response.ok('Showing book by index: $index'); | |
} | |
return new Response.ok('Showing all books.'); | |
} else if (reqMethod == 'POST') { | |
return new Response.ok('Added a book.'); | |
} else if (reqMethod == 'PUT') { | |
return new Response.ok('Added a book.'); | |
} else if (reqMethod == 'DELETE') { | |
return new Response.ok('Added a book.'); | |
} | |
// If all else fails | |
return new Response(405, null, 'Not sure what you\'re asking here'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment