Backend Dart

Lebe.write
5 min readAug 1, 2023

--

Yeah, you heard it right, Backend Dart. Dart boasts a range of server-side frameworks akin to Node.js for JavaScript and Django for Python. These powerful server-side frameworks for Dart open up a world of possibilities, providing developers with a plethora of options to build robust and efficient backend systems.

In this article, we will delve into the diverse landscape of Dart’s server-side frameworks, exploring their features and functionalities that empower developers to create scalable and performant applications.

Shelf:

Shelf is a powerful and flexible web server framework for Dart, designed to handle HTTP requests and build web applications with ease. It provides a minimalist, composable architecture, allowing developers to piece together middleware and handlers to create custom server-side logic. With its simplicity and modularity, Shelf enables developers to focus on crafting efficient and scalable web applications. Whether you are building RESTful APIs, serving static content, or handling complex routing, Shelf offers the tools and extensibility to meet a variety of server-side needs in Dart.

here is a sample code check shelf GitHub repo for more information.

sample code snippet

import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;

void main() async {
var handler =
const Pipeline().addMiddleware(logRequests()).addHandler(_echoRequest);

var server = await shelf_io.serve(handler, 'localhost', 8080);

// Enable content compression
server.autoCompress = true;

print('Serving at http://${server.address.host}:${server.port}');
}

Response _echoRequest(Request request) =>
Response.ok('Request for "${request.url}"');

Dart Frog

Created and maintained by the good brother at Very Good Ventures 🦄 , is a fast, minimalistic backend framework for Dart 🎯. The goal of Dart Frog is to help developers effectively build backends in Dart. Currently, Dart Frog is focused on optimizing the process of building backends that aggregate, compose, and normalize data from multiple sources.

The feature included in dart frog are:

✅ Dart Dev Tools ⚙️

✅ File System Routing 🚏

✅ Index Routes 🗂

✅ Nested Routes 🪆

✅ Dynamic Routes 🌓

✅ Middleware 🍔

✅ Dependency Injection 💉 etc…

check out DartFrog website for more info.

sample code snippet

import 'package:dart_frog/dart_frog.dart' ;

Reponse OnRequest(RequestContext context){
return Response(
body:"A fast, minimalistics backend framework for Dart"
);
}

Serverpod

Serverpod is a next-generation app and web server, built for the Flutter community. It allows you to write your server-side code in Dart, automatically generate your APIs, and hook up your database with minimal effort. Serverpod is open-source, and you can host your server anywhere.

The feature included in serverpod are:

✅ Code generation

✅ World-class logging

✅ Built-in caching

✅ Easy to use ORM

✅ File uploads

✅ Data streaming and many more…

Check out Serverpod website for more info.

Sample code snippet

// server code

// Creates an endpoint called ‘example’
class ExampleEndpoint extends Endpoint {

// Endpoint method to be called from client.
Future<String> hello(
Session session, String name) async {
return ‘Hello $name’;
}
}

// =========================================

// Client code.

// Client that can connect to the pod.
var client = Client (‘https://myapi.com/’);

// Calling generated client code.
var result =
await client.example.hello(‘World’);

// ‘result’ will be ‘Hello World’.

Alfred

If you have ever used expressjs before you should be right at home ALRED is a performant, expressjs-like web server/rest api framework that's easy to use and has all the bits in one place.

The core principles of Alfred include:

  • A minimum of dependencies,
  • A minimum of code and sticking close to dart core libraries — easy to maintain!
  • Ease of use
  • Predictable, well-established semantics

Check out Alfred website for more info.

Sample code snippet:

import 'package:alfred/alfred.dart';

void main() async {
final app = Alfred();

app.get('/example', (req, res) => 'Hello world');

await app.listen();
}

Serveme

ServeMe is a simple and powerful modular server framework. It allows us to easily create backend services for both mobile and web applications.

The core feature of Serveme include:

  • WebSockets and TCP sockets
  • Configuration files
  • Establishing client connection to a remote server
  • Logs and errors
  • Console commands and more …

Check out Serveme repo for more info.

sample code snippet:

import 'package:serveme/serveme.dart';

Future<void> main() async {
final ServeMe<ServeMeClient> server = ServeMe<ServeMeClient>();
await server.run();
}

Get Server

GetServer allows you to write backend applications with Flutter. Everything here is familiar, from the widgets, to the setState, initState and dispose methods, to the way you manage your projects with GetX using controllers and bindings.

Check out Getserver repo for more info.

sample code snippet

import 'package:get_server/get_server.dart';

void main() {
runApp(
GetServerApp(
home: Home(),
),
);
}

class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text('Welcome to GetX!');
}
}

Conclusion

And that all flocks I hope you found this article insightful and added knowledge on backend dart, Thanks for reading,leave a like, and see you in the next article.

Goodbye, happy coding.

--

--