Quack Service & Controller

We will create our Quack service and controller

Having created the model we can now begin implementing the CRUD functionalities. We want to list, create, read, update, and delete the Quacks.

Quack Service#

We start with the service, so let's go over them one by one. We can start with the imports:

List Quacks#

The list method is straightforward. With larger applications you would want to have some filtering, sorting and pagination, but that is a bit outside of the scope of this course, and is usually handled by ORMs

Create Quack#

With a failsafe for missing data, this method creates a Quack with created_by and text while using default values for the rest.

Read Quack#

Here we simply pass in the id and return either the Quack or null

Update Quack#

As only the creator can edit a Quack, we don't need to update anything else than the text.

Delete Quack#

Simply deleting the Quack based on the ID, we don't need to return anything and just assume that something was deleted if no error was thrown.

Quack controller#


This page is a preview of Build and deploy a REST API with Deno

Start a new discussion. All notification go to the author.