Before you create the directory and start writing the controller, start frourio in dev mode.
Now that we're ready, let's create a
memo/ directory in
Then three files,
$relay.ts and the main one,
controller.ts, are automatically generated under the directory we just created.
We just ran frourio in dev mode, and it does two things while it's running:
- Auto-generate files when the directory is added to the
$server.tsif there are changes in
index.ts - API type definitions#
Write the API request type definition.
$relay.ts - Bridge to the server framework#
A bridge between Fastify and the controller. Files starting with
$ are auto-generated, so you don't have to edit them.
controller.ts - The definition of controllers#
This file defines the behavior of the controller that received the request.
The controller is defined in
$server.ts by passing a function that returns response data for each HTTP method as an argument to
We can see that route definitions are automatically generated.