Giter VIP home page Giter VIP logo

dart_frog's Introduction

Dart Frog Logo Dart Frog Logo

ci coverage style: very good analysis License: MIT Powered by Mason

A fast, minimalistic backend framework for Dart 🎯

Developed with πŸ’™ by Very Good Ventures πŸ¦„

Documentation πŸ“

For official documentation, please visit https://dartfrog.vgv.dev.

Packages πŸ“¦

Package Pub
dart_frog pub package
dart_frog_gen pub package
dart_frog_cli pub package
dart_frog_web_socket pub package
dart_frog_auth pub package

Quick Start πŸš€

Prerequisites πŸ“

In order to use Dart Frog you must have the Dart SDK installed on your machine.

Installing πŸ§‘β€πŸ’»

# πŸ“¦ Install the dart_frog cli from pub.dev
dart pub global activate dart_frog_cli

Creating a Project ✨

Use the dart_frog create command to create a new project.

# πŸš€ Create a new project called "my_project"
dart_frog create my_project

Start the Dev Server 🏁

Next, open the newly created project and start the dev server via:

# 🏁 Start the dev server
dart_frog dev

πŸ’‘ Tip: By default port 8080 is used. A custom port can be used via the --port option.

Create a Production Build πŸ“¦

Create a production build which includes a DockerFile so that you can deploy anywhere:

# πŸ“¦ Create a production build
dart_frog build

Create New Routes and Middleware πŸ›£οΈ

To add new routes and middleware to your project, use the dart_frog new command.

# πŸ›£οΈ Create a new route "/hello/world"
dart_frog new route "/hello/world"

# πŸ›£οΈ Create a new middleware for the route "/hello/world"
dart_frog new middleware "/hello/world"

Goals 🎯

Dart Frog is built on top of shelf and mason and is inspired by many tools including remix.run, next.js, and express.js.

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 which aggregate, compose, and normalize data from multiple sources.

Dart Frog provides a simple core with a small API surface area in order to reduce the learning curve and ramp-up time for developers. In addition, Dart Frog is intended to help Flutter/Dart developers maximize their productivity by having a unified tech stack that enables sharing tooling, models, and more!

Extensions πŸ’»

  • VS Code: extends VS Code with support for Dart Frog and provides tools for effectively managing Dart Frog projects within VS Code.

dart_frog's People

Contributors

alestiago avatar davidmartos96 avatar dependabot[bot] avatar developerjamiu avatar diruffy avatar easazade avatar erickzanardo avatar feduke-nukem avatar felangel avatar femalemonkeyman avatar frezyx avatar gabrielrozendo avatar github-actions[bot] avatar jamesblasco avatar jsgalarraga avatar jxstxn1 avatar kylefin avatar luiscib3r avatar mtwichel avatar piotrfleury avatar quentin7b avatar renancaraujo avatar ryanramchandar avatar ryzizub avatar scarletteliza avatar sinakhe avatar ska2519 avatar thecodexhub avatar tomarra avatar wolfenrain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dart_frog's Issues

feat: expose HttpConnectionInfo

Description

As a developer, I want to have easy access to the HttpConnectionInfo so that I can access the remote address and/or port.

This can be surfaced via the RequestContext:

Response onRequest(RequestContext context) {
  final connectionInfo = context.connectionInfo;
}

[proposal] feat: provider's create param should allow asynchronous functions

Description

As a developer, I would like to inject dependencies like so:

return handler.use(
    provider<SecretManagerApi>((context) async {
        final client = await clientViaApplicationDefaultCredentials(scopes: []);
        return SecretManagerApi(client);
    }),
);

However, this will result in a complier error as the create function passed to provider must be synchronous.

I propose we change the create function's definition from

T Function(RequestContext context) create

to

FutureOr<T> Function(RequestContext context) create

Pros and Cons

The upside would be that you can write code like the example above. The downside is that it would required the read<T> function to return FutureOr<T>, which would be a breaking change and required you to await every call to read.

example:

Future<Response> onRequest(RequestContext context) async {
  final secretManagerApi = await context.read<SecretManagerApi>();
  return Response();
}

I argue that's not a major breaking change because

  1. dart_frog is still very young and experimental
  2. I would be willing to bet 90% of all Handlers are async anyway (for reading from a database or calling an external API, for example). Thus, this would just mean adding a few more awaits in your code.

Other Workarounds

There are a few workarounds that we've tried that work today:

1. Inject a Future that returns the dependency

return handler.use(
    provider<Future<SecretManagerApi>>((context) async {
        final client = await clientViaApplicationDefaultCredentials(scopes: []);
        return SecretManagerApi(client);
    }),
);

and to read

Future<Response> onRequest(RequestContext context) async {
  final secretManagerApi = await context.read<Future<SecretManagerApi>>();
  return Response();
}

This works, but I think the syntax of reading a Future of a dependency is pretty clunky imo.

2. A readAsync extension on RequestContext

extension RequestContextAsync on RequestContext {
  Future<T> readAsync<T>() => read<Future<T>>();
}

to inject:

return handler.use(
    provider<Future<SecretManagerApi>>((context) async {
        final client = await clientViaApplicationDefaultCredentials(scopes: []);
        return SecretManagerApi(client);
    }),
);

and to read:

Future<Response> onRequest(RequestContext context) async {
  final secretManagerApi = await context.readAsync<SecretManagerApi>();
  return Response();
}

This also works, but imo it would be confusing for new developers to decide when to use read and when to use readAsync, and it wouldn't be in official documentation.


Finally, I have a branch that displays this functionality here: https://github.com/mtwichel/dart_frog/tree/feat/async-create-functions (not PR ready because of testing, but could become so fairly quickly I believe)

I'm curious what everyone thinks! Thanks for everything VGV πŸ’™

fix: multiple file structures can make it unclear where code will be executed

Description

I hesitate to call this a bug because nothing is broken, but I think I found a quirk that needs addressed either by changing the code or documenting it somewhere.

You currently can define a route with a file name (routes/hello.dart) and with a folder name and index.dart (routes/hello/index.dart). In this case, it is unclear to the developer which hander will be called, if any.

In my testing, it seems the nested index.dart handler will be called. I think this is fine default behavior, but I can imagine that being confusing to someone new with the package if they end up in a weird state like this.

Steps To Reproduce

  1. Clone this minimum reproduction
  2. Notice the file structure. We have a hander on routes/hello.dart and routes/hello/index.dart
  3. Run dart_frog dev and send a request to /hello
  4. Notice it says Hello from hello/index.dart

Expected Behavior

Personally, I would expect this kind of case to display an error in the CLI, and also an error with dart_frog build.

I could also see an argument for having this just be the intended behavior (as long as it's consistent), but in that case I really think it should be clearly documented so if someone ends up in that situation and don't understand why a handler isn't being called, it's easy for them to solve their problem.

Thanks VGV πŸ’™ I'm excited to hear what you think.

fix: windows route generation

A clear and concise description of what the bug is.

Steps To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected Behavior

A clear and concise description of what you expected to happen.

final

If applicable, add screenshots to help explain your problem.

Additional Context

Add any other context about the problem here.

fix: Dockerfile build fails

Description

Deploying the project on Heroku via Dockerfile (produced by dart_frog build) reports an error:

Screenshot 2022-07-01 at 4 23 00 PM

I have also tried using the Dockerfile on my local Docker and the build fails with the same error.

Steps To Reproduce

  1. build your dart frog project
  2. try deploying via dockerfile

Temporary fix
Removing the following lines from the Dockerfile fixed the error:
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/bin/server /app/bin/

How to modify the entry point (ex: to open a connection with Mongo dart)

Hi everyone, thanks for bringing such an amazing framework to the Dart/Flutter community.

I was wondering what would be the best way to modify the entry point to open a connection with Mongo Dart for example. I looked at the youtube demo video and I saw that you generate the entry point in the build file only.

Is there any other way to have specific code run when the server is started?

Thanks.

fix: build server

Build server does not start after executing dart build/bin/server.dart command

feat: simpler support for freezed

Description

I believe a lot of people in the dart community are using pubs like freezed. When I was recently trying to use it, I realised I can't just have a models folder in the root and use freezed like that, I had to put the dart files that would be generated under the lib directory.
I feel like this kind of makes it lose the point of dart_frog not using the libs folder.
Perhaps I missed something here?

Same thing would be happening with dart doc .. Although I am aware that's not really needed if there is eventually swagger support.

Requirements

  • A way to use freezed naturally with dart_frog

feat: HTML template support

Description
As a user, I want to be able to respond with an HTML template.

If we don't want to implement it in this core project. Would love to see separate project to support it as a plugin either by VG team themselves or by the community.

feat: possibility to combine DI and middleware

Description

Currently when we want to declare a middleware we use this:

Handler middleware(Handler handler) {
  return (context) async {
    final response = await handler(context);
    return response;
  };
}

But adding a dependency injection inside the return doesn't seem to be possible like this:

Handler middleware(Handler handler) {
  return (context) async {
    handler.use(provider<String>((context) => 'sometext'));
    final response = await handler(context);
    return response;
  };
}

instead we have to declare the injection outside:

Handler middleware(Handler handler) {
  return (context) async {
    final response = await handler(context);
    return response;
  }.use(provider<String>((context) => 'sometext'));
}

Currently it doesn't seem like we can use the data in the request to inject anything.
The main issue I am having with this is, I want to implement some sort of an authentication and of course I don't want to check for the authentication inside the routes separately every time.
Since we don't have annotations like in flask, I thought the answer for that is inside the middleware, but I can't decode a JWT which would be asynchronous in this case and then pass it down to the connected routes. The same goes for the initialization of a db connection.

Would there be any way to pass down data inside the return in a middleware or is there perhaps a different way to do this?

feat: Protocol Buffers Support (protobuf)

Description

Protocol Buffers or "protobuf" is a tool (developed by Google) to provide mechanisms to serialize structured data in a very efficient way making the data transferred very small and the serialization blazing fast!.

Proposal

It would be great if dart_frog supported protobuf or at least leave a clear way to be handled by a plugin or brick.

Requirements

  • Response Models for the endpoints to be automatically generated based on .proto files.
  • Generated Models can be bundled in a shared package between the server and the client applications.

Additional Context

Dart is supported!

fix: bad state: The 'read' method can only be called once

Description

Seeing the following:

Asynchronous error
Bad state: The 'read' method can only be called once on a shelf.Request/shelf.Response object.

package:shelf/shelf_io.dart 143:11  handleRequest

When running the example and visiting http://localhost:8080 in the browser.

feat: entity / models management

Description

Manage models and models relations to have a complete CRUD backend with paging / searching with best practices API (REST/GraphQL)

Requirements

  • Checklist of requirements to be fulfilled

Additional Context

Add any other context or screenshots about the feature request go here.

feat: Join the force

Description

There is ServerPod project which is an awesome backend for Dart/Flutter. I suggest to unite your efforts with ServerPod guys because Dart really suffer with backend projects as mentioned in my post

chore: Open Discussion on Github

Description

I think it will be better to open the Discussion tab in Github as there could be a lot of topics that should go into the Discussion tab before even making it into an Issue or PR.

feat: improve hot reload reporting when files are modified

Description

As a developer, whenever a file is modified, two events are reported: ADD, REMOVE which results in two codegen cycles and errors are reported by the hot reload process due to the temporary invalid state. We should improve this so that only relevant errors are surfaced to the developer so as to avoid confusion and keep output clean/concise.

Need to experiment with optimizing this to avoid an unnecessary codegen cycle (debounce).

feat: authentication

Description

Firstly, I did see this in the contributing guide:

At this time, we welcome bug tickets but will not be accepting feature requests because the roadmap and scope of this project is still being defined.

However I feel this is a very important feature to support.

In order to build a backend which enables users to register and login to your app or to monitor 3rd-party apps API usage of public APIs, authentication needs to be in place.

I would guess that the majority of backends being built would only care about user auth and not care about enabling 3rd party apps to use the APIs.

Some of the different types of authentication which could be added:

  • JWT tokens
  • Bearer token
  • API keys
  • OAuth

In case it may help with OAuth implementation, I did stumble upon this OAuth example in the past which may help inspire the implementation for OAuth support for dart_frog.

Requirements

  • Authentication support is added
  • Documentation is provided on how to setup authentication

feat: Dart API Client Generation

Description

As a developer, I want to be able to autogenerate a Dart API Client library based on my Dart Frog application code so that I can seamlessly integrate with my Dart Frog backend without having to manually write an API client layer.

Requirements

  • Development Server Support (Hot Reload Compatibility)
  • Production Server Support
  • Strongly Typed API
  • High Quality Code
    • compatible w/very_good_analysis
    • fully tested
    • ci workflow (using very_good_workflow)
    • fully documented (dart doc)

docs: Fun Fact

Description
Way back before Dart v1, the transpiler currently known as dart2js used to be called 'frog'. :)

Benchmarking

Setup

dart_frog create my_project
cd my_project/
dart_frog build
cd build/
dart compile exe bin/server.dart -o bin/server
./bin/server

Benchmark
ab -n 20000 -c 10 "http://127.0.0.1:8080/"

Output

This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
apr_socket_recv: Operation timed out (60)
Total of 16349 requests completed

feat: ORM

I think ORM and documentation for connecting the app to a database would be helpful!

feat: add Response.unknown() constructor

Description

Currently, if a request is sent and it does not match a route, it returns a 404 route with a body of Route not found.

Since (for now), it seems dart_frog won't support specifying request methods in the builder (judging from #57), we manually should return the 404 route in the handler. It would be super helpful to have a response constructor to handle this case.

For syntax, I'm thinking

  • Call it Response.unknown() following from Response.json() and Response.bytes()
  • Have it automatically have a status code of 404, and a body the same as when no route is detected.

Not a necessity, but in my experience with dart_frog so far, it would be really nice to have.

Additional Thoughts
Out of scope for this issue, but should adding the option for a custom 404 response be a good idea? Maybe a top level file named _404.dart? If people are excited about it, let's make another issue πŸ’™

The filename, directory name, or volume label syntax is incorrect on Windows 10

Description

The filename, directory name, or volume label syntax is incorrect.

dart_frog dev

After running the above command in cmd

βœ“ Running on http://localhost:8080 (3.3s)
The Dart VM service is listening on http://127.0.0.1:8181/45EwVYB4AYs=/

The Dart DevTools debugger and profiler is available at: http://127.0.0.1:8181/45EwVYB4AYs=/devtools/#/?uri=ws%3A%2F%2F127.0.0.1%3A8181%2F45EwVYB4AYs%3D%2Fws

.dart_frog/server.dart:7:8: Error: Error when reading '.dart_frog/..%0Doutes/index.dart': The filename, directory name, or volume label syntax is incorrect.

import '..\routes/index.dart' as routes_index;
       ^
.dart_frog/server.dart:29:29: Error: Undefined name 'onRequest'.
    ..all('/', routes_index.onRequest);
                            ^^^^^^^^^

Environment

flutter doctor -v
[√] Flutter (Channel stable, 3.0.0, on Microsoft Windows [Version 10.0.19043.1706],
    locale en-US)
    β€’ Flutter version 3.0.0 at C:\src\flutter
    β€’ Upstream repository https://github.com/flutter/flutter.git
    β€’ Framework revision ee4e09cce0 (2 weeks ago), 2022-05-09 16:45:18 -0700
    β€’ Engine revision d1b9a6938a
    β€’ Dart version 2.17.0
    β€’ DevTools version 2.12.2

Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    β€’ Android SDK at C:\Users\abdullah\AppData\Local\Android\sdk
    β€’ Platform android-31, build-tools 30.0.3
    β€’ Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    β€’ Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
    β€’ All Android licenses accepted.

[√] Chrome - develop for the web
    β€’ Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.4)
    β€’ Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    β€’ Visual Studio Community 2022 version 17.0.32014.148
    β€’ Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.1)
    β€’ Android Studio at C:\Program Files\Android\Android Studio
    β€’ Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    β€’ Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    β€’ Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)

[√] VS Code (version 1.67.2)
    β€’ VS Code at C:\Users\abdullah\AppData\Local\Programs\Microsoft VS Code
    β€’ Flutter extension version 3.40.0

[√] Connected device (3 available)
    β€’ Windows (desktop) β€’ windows β€’ windows-x64    β€’ Microsoft Windows [Version
      10.0.19043.1706]
    β€’ Chrome (web)      β€’ chrome  β€’ web-javascript β€’ Google Chrome 101.0.4951.67
    β€’ Edge (web)        β€’ edge    β€’ web-javascript β€’ Microsoft Edge 100.0.1185.44

[√] HTTP Host Availability
    β€’ All required HTTP hosts are available

β€’ No issues found!

fix: route not found if you have folder with file under parameter

Description

Basically, if you have nested folder including parameters the routes are not being found.

Steps To Reproduce

  1. Create simple structure: test/[id]/test2/index.dart
  2. Try to execute the call, the route will not be found.

Expected Behavior

The route should be reachable as test/$id/test2 and test/$id/test2/

Additional Context

The problem does not appear if you put index.dart directly in [id] folder.

docs: official documentation site

Description

it would be a better approach for a new framework or library, to create a documentation repository or a web page containing the official documents for the framework.

contributors can work on the issue or to a new feature and also update the docs, and new users can easly understand how it works

Requirements

  • A repository or one branch in the same repo with GHPages

fix: dev server hot reload stability

Description

As a developer, I want the development server to have a robust hot-reload mechanism that can recover from errors so that I can have a seamless developer experience without having to constantly restart the dev server.

Steps To Reproduce

  1. Generate a new Dart Frog project
  2. Start the development server
  3. Create an new route with an incomplete/invalid implementation
  4. Observe the route is not available
  5. Finish updating the route to have a complete/valid implementation
  6. Observe the route is still not available
  7. Restart the development server
  8. Observe the route is now available

Expected Behavior

As a developer, I expect to have the dev server report any errors and have a resilient hot-reload mechanism that doesn't require restarting the server manually.

feat: How can I run Dart frog with HTTPS support (SSL)?

Description

How can I configure dart frog to allow accessing the server via HTTPS? I know that I need to setup the certificate on my server accordingly. However, it seems that I'd also need to adjust how the server is started via shelf? Does dart frog so far support HTTPS connections?

feat: Improve ease of implementation

Description

This is a great initiative. But I feel like the implementation is not very intuitive. Have you ever played with a framework called - nest.js. It's incredibly straightforward to build production-scale applications. I wish dart_frog could follow a similar pattern. Let me know what you guys think about it. Cheers 🍻

Requirements

  • Annotations for controller - endpoints and websockets,
  • Constructor Injectable services (for inversion of control and Dependency Injection)

fix: build on windows fail on cp

Description

When dart_frog build is run on Powershell on Windows, it's fail.

Steps To Reproduce

  1. Go to the dart_frog project's
  2. Run 'dart_frog build' on powershell
  3. See error

Error

PS C:\Users\*******************\dart_frog_project> dart_frog build
βœ“ Bundling sources (0.2s)
'cp' n'est pas reconnu en tant que commande interne
ou externe, un programme exβ€šcutable ou un fichier de commandes.

It means that the command 'cp' is not recognized has internal command.

Environment

flutter doctor -v

[√] Flutter (Channel stable, 3.0.1, on Microsoft Windows [version 10.0.19044.1466], locale fr-FR)
    β€’ Flutter version 3.0.1 at C:\flutter
    β€’ Upstream repository https://github.com/flutter/flutter.git
    β€’ Framework revision fb57da5f94 (5 days ago), 2022-05-19 15:50:29 -0700
    β€’ Engine revision caaafc5604
    β€’ Dart version 2.17.1
    β€’ DevTools version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    β€’ Android SDK at C:\Users\Tof\AppData\Local\Android\sdk
    β€’ Platform android-32, build-tools 32.0.0
    β€’ Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    β€’ All Android licenses accepted.

[√] Chrome - develop for the web
    β€’ Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2020.3)
    β€’ Android Studio at C:\Program Files\Android\Android Studio
    β€’ Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    β€’ Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code (version 1.67.2)
    β€’ VS Code at C:\Users\Tof\AppData\Local\Programs\Microsoft VS Code
    β€’ Flutter extension version 3.40.0

[√] Connected device (3 available)
    β€’ Windows (desktop) β€’ windows β€’ windows-x64    β€’ Microsoft Windows [version 10.0.19044.1466]
    β€’ Chrome (web)      β€’ chrome  β€’ web-javascript β€’ Google Chrome 101.0.4951.54
    β€’ Edge (web)        β€’ edge    β€’ web-javascript β€’ Microsoft Edge 99.0.1150.55

[√] HTTP Host Availability
    β€’ All required HTTP hosts are available

! Doctor found issues in 1 category.

Prisma like

during my working on the backend, I used to use Prisma to manage my databases,
I would like to know how to integrate Prisma or use the same ORM with dart frog,

I will be using this SDK for my personal project to test it and see what we can Improve on it
So on production, we can switch from nestJS to dart_frog.

fix: middlewares wont work with dynamic routes

Description

Middlewares inside dynamic routes are not recognized.

Steps To Reproduce

  1. Create a frog server with the following route structure
routes/
  - _middleware.dart
  - [id]/
    - index.dart
    - _middleware.dart
  1. On the root middleware, put the following content:
import 'package:dart_frog/dart_frog.dart';

Handler middleware(Handler handler) {
  return handler
      .use(provider<String>((context) {
    return 'root middleware haha';
  }));
}
  1. On the middleware under /[id], put the following content:
import 'package:dart_frog/dart_frog.dart';

Handler middleware(Handler handler) {
  return handler
      .use(provider<String>((context) {
    return 'id middleware hihi';
  }));
}
  1. On /[id]/index.dart put the following content:
import 'package:dart_frog/dart_frog.dart';

Response onRequest(RequestContext context) {
  final thingy = context.read<String>();
  return Response(body: 'result: $thingy');
}
  1. Start the server and go to http://localhost:8080/someid
  2. See the result: result: root middleware haha

Expected Behavior

The handler at /[id]/index.dart should; receive a context with information for the closest middleware, not the root one.

Additional Context

Reproducible with the CLI version 0.0.2-dev.7

feat: Flutter integration

Description

This isn't so much a precise feature request as much as it is clarity and discussion on any Flutter integration plans. Remix and NextJS are both mentioned as being inspiration for Dart Frog which sparked some questions. Both Remix and NextJS are more than just a minimal backend framework. They are very opinionated frameworks around React and provide robust SSR and SSG features (among other things). That begs the question, how closely tied to Flutter will Dart Frog become long term? Will Dart Frog stay as an agnostic backend server (like express) or will it transform into something resembling NextJS/Remix but for Flutter?

It's worth mentioning that I am not vouching either way but am more curious on the maintainer's thoughts.

feat: add ability to install dart_frog_cli from different package managers

Description

In order to make the tool more accessible for non-Dart developers, it'd be interesting to have the ability to install dart_frog_cli from different package managers, like Homebrew or Chocolatey.

Requirements

  • Install using dart pub global
  • Install using brew
  • Install using chocolatey
  • Install using apt (Ubuntu)

Additional Context

If extra context is needed, we can see how mason already supports this: https://github.com/felangel/mason/tree/master/packages/mason_cli#installation

feat: API Documentation Generation

Description

As a developer, I want to be able to generate Open API (or similar) documentation for my Dart Frog application so that other developers are able to seamlessly integrate with the API and are aware of the full API specification.

Requirements

  • Development Support (Hot Reload Compatibility)
  • Production Support
  • Open API Specification (or similar)
  • Endpoint to view the documentation
  • Documentation should be interactive (try it now)

[proposal] docs: make examples directory contain multiple examples

Description

As a developer, it would be helpful to see example projects for different use cases of dart_frog (ie using a database, using protobufs, a full-stack example with a Flutter app, ect)

I propose we move the existing example into a new top level directory called examples. We can call the existing example basic or something like that.

The new folder structure would look something like this:

…
docs
packages
examples
| β€” basic
| β€” postgres
| β€” full stack
| β€” …

Another nice feature is the examples could serve as integration tests and making sure no changes break the examples.

Alternative
An alternative structure is to create a separate repo for examples, maybe called dart_frog_examples. This makes discoverability a bit harder, but also means pull requests for examples wouldn’t clog up the main repository.

LMK what you think! πŸ’™

feat: web socket support

Description

Hello,
first of all: Thank you for this package. After aqueduct was closed, there was no real alternative to create the server in the same language as the flutter application.
Currently I want to built a real time chat application. For this, I need to support web sockets to communicate with the client.
https://pub.dev/packages/shelf_web_socket is a shelf socket plugin that can be used for this.

Requirements

  • Checklist of requirements to be fulfilled

Additional Context

-

fix: Creating routes/filename.dart results to Internal Server Error

Description
If you create hello.dart inside the routes folder and try to access localhost:8080/hello results to internal server error but when / is added to the buildHandler it works

if you create hello.dart inside routes folder this is what buildHandler looks like

Handler buildHandler() {
  const pipeline = Pipeline();
  final router = Router()
    ..all('/', routes_index.onRequest)
    ..all('hello', routes_hello.onRequest);
  return pipeline.addHandler(router);
}

when you try to access localhost:8080/hello an error is been throw internal server error
but if i modify it

Handler buildHandler() {
  const pipeline = Pipeline();
  final router = Router()
    ..all('/', routes_index.onRequest)
    ..all('/hello', routes_hello.onRequest);
  return pipeline.addHandler(router);
}

Expected Behavior
/ should be added new routes under buildHandler automatically

Handler buildHandler() {
  const pipeline = Pipeline();
  final router = Router()
    ..all('/', routes_index.onRequest)
    ..all('/hello', routes_hello.onRequest);
  return pipeline.addHandler(router);
}

feat: logger support

Description

As a developer, I want to be able to have either integrated 1st party support or a recommended 3rd party logger which seamlessly integrates with dart_frog and provides the functionality described in the requirements section.

Requirements

  • Standard Logging Levels
  • Flexible API which can support logging-specific requirements for various cloud platforms
  • API which can support configuring log-levels based on the environment (e.g. debug in development and notice in production)

docs: json_serializable only works within lib folder

Hey,

I played around with dart_frog today and since I'm used to json_serializable I used it for my models. From a flutter project and dart package perspective it's pretty clear the model files have to be inside the lib folder to be json-generated, but from the dart_frog perspective I first did not create a lib folder but just created a models folder on the same level like the routes folder. This might be stupid and totally clear it doesn't work - I don't know - but my json-generation did not generate any files and also did not give me any error message. It took me some time to get to this moment where I was like: "oh... I have to put it inside the lib folder" to make it work.

Is my assumption true by putting it in the lib folder is the only possible way to generate those models or did I miss something or my configuration is broke etc.?

Best regards, keep up the great work <3
Verry

fix: exception when running dart_frog build

Description

I just created a project with cli and then changed nothing. when i wanted to build the project the cli would give this exception

βœ“ Bundling sources (0.1s)
An exception occurred while executing hook: pre_gen.dart.
Error: FileSystemException: Rename failed, path = 'C:\Users\madi\AppData\Local\Temp\943e167a' (OS Error: The system cannot move the file to a different disk drive.
, errno = 17)

Steps To Reproduce

  1. create a project with dart_frog create
  2. run dart_frog build

Expected Behavior

project should been build for production

Additional Context
Dart SDK version: 2.17.6 (stable) (Tue Jul 12 12:54:37 2022 +0200) on "windows_x64"

feat: http method specification per handler

Description

There should be a way to define method-based callbacks. I was thinking of a couple of ways to possibly do this:

  1. Filenames; we could use file-naming conventions that contain the method used for the callback in it.
routes
└───user
β”‚   β”‚   get.dart
β”‚   β”‚   post.dart
└───photos
β”‚   β”‚   [photoId]get.dart
β”‚   β”‚   post.dart
β”‚
...
  1. Different callbacks; maybe different callbacks could be registered for each method available:
Future<Response> onGetRequest(RequestContext context) async {
  return Response(body: 'this is a GET method');
}

Future<Response> onPostRequest(RequestContext context) async {
  return Response(body: 'this is a POST method');
}

Future<Response> onPutRequest(RequestContext context) async {
  return Response(body: 'this is a PUT method');
}

Future<Response> onDeleteRequest(RequestContext context) async {
  return Response(body: 'this is a DELETE method');
}

This is what I came up with, but if you think of something better I'd love to hear it :))

Requirements

  • codegen-method-based mapping to a callback
  • If, say, an endpoint with a GET method exists but it gets called with a POST method, it will return a 404 NOT FOUND.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.