You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Developed with 💙 by [Very Good Ventures][very_good_ventures_link] 🦄
5
+
4
6
[![ci][ci_badge]][ci_link]
5
7
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
6
8
[![License: MIT][license_badge]][license_link]
@@ -47,7 +49,9 @@ Create a production build which includes a `DockerFile` so that you can deploy a
47
49
dart_frog build
48
50
```
49
51
50
-
## Routes 🚏
52
+
## Documentation 📝
53
+
54
+
### Routes 🚏
51
55
52
56
In Dart Frog, a route consists of an `onRequest` function (called a route handler) exported from a `.dart` file in the `routes` directory. Each endpoint is associated with a routes file based on its file name. Files named, `index.dart` will correspond to a `/` endpoint.
Dart Frog supports dynamic routes. For example, if you create a file called `routes/posts/<id>.dart`, then it will be accessible at `/posts/1`, `/posts/2`, etc.
92
96
97
+
Routing parameters are forwarded to the `onRequest` method as seen below.
Middleware in Dart Frog allows you to execute code before and after a request is processed. You can modify the inbound request and outbound responses by adding headers, provide dependencies, and more!
109
+
Middleware in Dart Frog allows you to execute code before and after a request is processed. You can modify the inbound request and outbound responses, provide dependencies, and more!
104
110
105
111
In Dart Frog, a piece of middleware consists of a `middleware` function exported from a `_middleware.dart` file within a subdirectory of the `routes` folder. There can only ever be once piece of middleware per route directory with `routes/_middleware.dart` being middleware that is executed for all inbound requests.
Middleware can also be used to provide dependencies to a `RequestContext` via a `provider`.
138
144
139
-
`provider` is a type of middleware that can return an object of type `T`and has access to a `RequestContext`. The `create` callback is called lazily and the injected `RequestContext` can be used to perform additional lookups to access values provided upstream.
145
+
`provider` is a type of middleware that can create and provide an instance of type `T` to the request context. The `create` callback is called lazily and the injected `RequestContext` can be used to perform additional lookups to access values provided upstream.
140
146
141
147
In the following example, we'll use a `provider` to inject a `String` into our request context.
In Dart Frog, we can unit test our route handlers and middleware effectively because they are just pure functions.
167
173
@@ -194,6 +200,8 @@ void main() {
194
200
195
201
In the above test, we're using `package:mocktail` to create a mock `RequestContext` and stub the return value when calling `context.read<String>()`. Then, all we need to do is call `onRequest` with the mocked context and we can assert that the response is what we expect. In this case, we're checking the statusCode and response body to ensure that the response is a 200 with the provided greeting.
196
202
203
+
For more information, see the [example][example_link] and our [roadmap][roadmap_link].
204
+
197
205
## Feature Set ✨
198
206
199
207
✅ Hot Reload ⚡️
@@ -225,9 +233,12 @@ In the above test, we're using `package:mocktail` to create a mock `RequestConte
0 commit comments