Overview
Getting Started

Getting started

In the following set of articles, we'll create a simple application will help us to understand the basics of the Zero framework.

Prerequisites

Before we start, make sure you have the following installed:

Setup

First, we need to create a new project using the Zero CLI:

zero new my_app

The project structure should look like this:

my_app
├── lib
   ├── controllers
      └── books_controller.dart
   ├── main.dart
   └── models
       └── book.dart
├── pubspec.lock
└── pubspec.yaml

Here is a brief description of the files and folders:

File/FolderDescription
libContains the source code of the application
lib/controllersContains the controllers of the application
lib/modelsContains the models of the application
lib/main.dartThe entry point of the application
pubspec.yamlThe configuration file of the application

The main.dart file is the entry point of the application and contains the following code:

import 'package:zero/zero.dart';
 
void main() {
  final server = Server(
    routes: [
        Route("/books", controller:(req) => BooksController(req)),
    ]
  );
}

The Server class is the main class of the framework and is responsible for handling the requests and responses. It takes a list of routes as a parameter. Each route contains a path and a controller. The path is the URL of the route and the controller is a function that takes a Request object as a parameter and returns a Response object.

Running the application

To run the application, use the following command:

zero run

Zero supports hot reload, so you don't need to restart the application every time you make a change. To disable hot reload, use the --no-watch flag:

zero run --no-watch