H4
H4 is a lightweight and delightful http framework written in Dart.
Project LinkMotivation
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:
- ✅Your server only includes and runs the code that is needed
- ✅ You can extend your server functionality easily without adding global plugins
- ✅ The usage is explicit and clean with less global middleware and plugins
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!
dart --version
Scaffold a dart app
dart create app -t console-simple
Then install H4
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.
dart run app.dart
Hello World.
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!🎉