RFC: We're building a better version of Dart Shelf

Shelf is a cool and wildly used web server framework for Dart. But since it was created, Dart has evolved, and best practices have changed. At Serverpod, we need a solid, modern web server. Therefore, we are creating a new package called Relic, which is based on Shelf but with several improvements:

  • We removed all List<int> in favor of Uint8List.
  • We made everything type-safe (no more dynamic).
  • Encoding types have been moved to the Body of a Request/Response to simplify the logic when syncing up the headers and to have a single source of truth.
  • We’ve added parsers and validation for all commonly used HTTP headers. E.g., times are represented by DateTime, cookies have their own class with validation of formatting, etc.
  • Extended test coverage.
  • There are lots of smaller fixes here and there.

Although the structure is very similar to Shelf, this is no longer backward compatible. We like to think that a transition would be pretty straightforward, and we are planning put a guide in place.

Before a stable release, we’re also planning on adding the following features:

  • We want to more tightly integrate a http server (i.e., start with HttpServer from dart:io as a base) with Relic so that everything uses the same types. This will also improve performance as fewer conversions will be needed.
  • Routing can be improved by using Radix trees. Currently, there is just a list being traversed, which can be an issue if you have many routes.
  • We’re planning to add an improved testing framework.
  • Performance testing and optimizations.

In addition, we’re planning to include Relic in Serverpod, both for powering our RPC and as a base for our web server. This would add support for middleware in our RPC. In our web server integration, we have support for HTML templates and routing. You also get access to the rest of the Serverpod ecosystem in terms of serialization, caching, pub-sub, and database integrations.

We would love your feedback before we finalize the APIs.

18 Likes

Hello, this sounds great! :sparkles:

Do you have any plans to support HTTP2/3?

1 Like

We need this kind of initiative.

ServerPod will have the hand on the product to model it for its needs and make it competitive.

Community will have an up to date package and can help with maintenance and consolidation for hardened production.

Dart team could focus elsewhere, they have much important stuffs to deal with.

Surely, in mid-term, the potential to be de facto solution for http/quic/grpc servers.

3 Likes

Yes, we want to support HTTP/2 short term, then probably build support for HTTP/3 a bit more into the future.

5 Likes

Thank you @BlueAquilae, this is exactly our thinking. We hope that Relic will be a win for everyone. Ideal scenario is to make it into Shelf 2.0, but that depends on how this lands with the Flutter team. :slightly_smiling_face:

1 Like

In my experience contributing to Dart/Flutter - it is usually easier when a change is very well defined and isolated, which limits the scope of conversation.

So from the list you provided above I’d split each of the bullet points into its own tracking issue in Github and clearly define the scope.

It would also be good to find a sponsor or interested Googler on the Dart team side of things (Flutter team is not involved in server side, AFAIK).

I know @kevmoo has been involved with Dart from early days and contributed a lot to things adjacent to server side (JsonSerializable, etc). But maybe you have better contacts these days. Or maybe Kevin can suggest a more up to date contact to server-side/shelf related parts of things.

I would definitely like to see this be an evolution of Shelf itself.

This sounds great, I’m hoping to spend some time playing with this over the holiday period. I’ve long advocated for more interest in Dart on the server and this looks really promising with some of the changes you are proposing.

Have you given any thought on maybe implementing (or wrapping existing implementations via FFI) for modern standards like OAuth 2.1 or WebAuthn for example?

Hey folks. I’d LOVE to figure out if there are some shared core types that could overlap here.

I’m mostly on holiday until ~Jan 6. Let’s kick off discussions in the new year!

6 Likes

Great initiative and thank you for taking the lead on offering first class tools for a full stack dart ecosystem.

How does this integrates with Serverpod?

If this is already part of the framework it would be great to have the option to create regular endpoints accesible to any http client (without the need to use the Serverpod client)?

We will be building an improved authentication package for Severpod. We are aiming to move any generic parts of that down to Relic, so that they can be used in other contexts too.

We are planning on adding Relic to Serverpod in two steps. The first step is to add a really competent web server (basically Relic plus templating/database/caching/pubsub support). As a second step, we’re refactoring Serverpod’s RPC to use Relic as well.

1 Like