November 2018
Intermediate to advanced
404 pages
10h 16m
English
The handler for creating a new journal entry decodes the JSON content received from the HTTP POST request on /journal/api/admin and saves it directly to the database:
func newEntry(_ req: Request) throws -> Future<JournalEntry> { return try req.content.decode(JournalEntry.self) .flatMap(to: JournalEntry.self) { entry in return entry.save(on: req) }}
It's a matter of making two calls, req.content.decode() and entry.save(on:), for the JournalEntry data model to decode and then save the new content into the database.
Check the handler for creating a new journal entry with the following curl command:
$ curl --header "Content-Type: application/json" \--request POST \--data '{"title":"New Entry","content":"This is a brand new ...Read now
Unlock full access