Use Dart on Servers with Dart Frog — The complete crash course
You can use Dart for so many things. One of them is the backend area. That’s why, I will show you today, how to use Dart Frog, a fast and minimalistic backend framework for Dart.
Note: You can find the whole source code provided in this tutorial here
Installation
First, we have to install the dart_frog cli. To do so, we will use the command dart pub global activate dart_frog_cli
. You should be familiar with those commands, otherwise, I recommend you to look up the basics of Flutter again. Now you can create a dart_frog project with dart_frog create my_project
.
The last thing we have to do is start the dev server. The default port is 8080
, but you can specify your custom port with --port
option. Navigate to your newly created project and execute dart_frog dev
.
Routes
Let’s talk about routes first. Routes are very important because they determine under which endpoint you can access data. For example, if you create a file in routes
folder called api.dart
, you will have an endpoint under /api
. It’s also possible to use dynamic routes. For example, you can create a file in routes/pages
called [id]
and it will be accessible under /pages/1
and /pages/2
… Okay, but how do we return data? First, we have to…