Dart Shelf server tutorial

Suragch
6 min readJan 5, 2024

Getting started with your first Shelf web server

source

If this is your first time using the shelf_router package, the documentation can be a little difficult to follow. Creative Bracket has a good video tutorial here, but this article will provide a written guide to get you started.

Other alternatives to Shelf include Dart Frog, Serverpod, Globe, or just plain Dart. Plain Dart is a little too low-level for me, and I’m still waiting for the other frameworks to establish themselves a little longer. I was burned when Aqueduct stopped being maintained, so I’d like something that I know will be stable for years. Shelf is maintained by the Dart team and its API hasn’t seemed to change much over the years.

Creating a new project

Create a new Dart server project. You can change my_shelf_server to whatever you want to call your project:

dart create -t server-shelf my_shelf_server

The -t argument is for selecting templates. In this case, the template is server-shelf. This will add the shelf and shelf_router packages to your project along with some sample server boilerplate code.

Exploring your project

Open the project and look at the file structure:

--

--