H4

H4 is a lightweight and delightful http framework written in Dart.

Project Link

Motivation

Dart is a powerful and rich language. I’m exploring the possibility of using dart as my go-to scripting language.

Philosophy

I love the design philosophy of h3.

A small core with a plethora of composable utility functions built in.

Composable utilities have huge advantages compared to traditional plugin/middleware approaches:

H4 is built for composability and ease of use, as we’ll see in the later parts of this document.

Tutorial

Enough yapping, let’s build something!


Terminal window
dart --version

Scaffold a dart app

Terminal window
dart create app -t console-simple

Then install H4

app/bin
dart pub add h4

Running the app

Everytime you make changes make sure to run (or re-run) the dart file containing your main function.

Terminal window
dart run app.dart

Hello World.
app.dart
import 'package:h4/create.dart';
void main() {
var app = createApp();
var router = createRouter();
app.use(router);
router.get("/", (event) => "Hello world!");
}

Now go to your browser and visit localhost:3000.

Brava!

Hello world!🎉

Let’s fetch some data!!