November 2018
Intermediate to advanced
404 pages
10h 16m
English
Thanks to the powerful database data-modeling offered in Vapor, the handler implementation for the HTTP GET /journal/api/ turns out to be straightforward:
func getAll(_ req: Request) throws -> Future<[JournalEntry]> { return JournalEntry.query(on: req).all()}
The operation for retrieving all existing journal entries is simply a call to the model's query(on:).all() methods.
Since the querying for entries in the database takes a finite amount of time, the transaction is asynchronous and the function returns the Future type.
For the myJournal web service, you do not use Leaf to generate any templates. Instead of testing your API with the web browser, it may be more convenient if you use the command-line ...
Read now
Unlock full access