Skip to content

Commit 0935704

Browse files
committed
docs: minor README updates
1 parent e02fad9 commit 0935704

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[![Dart Frog Logo][logo_white]][dart_frog_link_dark]
22
[![Dart Frog Logo][logo_black]][dart_frog_link_light]
33

4+
Developed with 💙 by [Very Good Ventures][very_good_ventures_link] 🦄
5+
46
[![ci][ci_badge]][ci_link]
57
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
68
[![License: MIT][license_badge]][license_link]
@@ -47,7 +49,9 @@ Create a production build which includes a `DockerFile` so that you can deploy a
4749
dart_frog build
4850
```
4951

50-
## Routes 🚏
52+
## Documentation 📝
53+
54+
### Routes 🚏
5155

5256
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.
5357

@@ -86,10 +90,12 @@ Future<Response> onRequest(RequestContext context) async {
8690
}
8791
```
8892

89-
### Dynamic Routes 🌓
93+
#### Dynamic Routes 🌓
9094

9195
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.
9296

97+
Routing parameters are forwarded to the `onRequest` method as seen below.
98+
9399
```dart
94100
import 'package:dart_frog/dart_frog.dart';
95101
@@ -98,9 +104,9 @@ Response onRequest(RequestContext context, String id) {
98104
}
99105
```
100106

101-
## Middleware 🍔
107+
### Middleware 🍔
102108

103-
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!
104110

105111
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.
106112

@@ -132,11 +138,11 @@ Handler middleware(Handler handler) {
132138
}
133139
```
134140

135-
### Dependency Injection 💉
141+
#### Dependency Injection 💉
136142

137143
Middleware can also be used to provide dependencies to a `RequestContext` via a `provider`.
138144

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.
140146

141147
In the following example, we'll use a `provider` to inject a `String` into our request context.
142148

@@ -161,7 +167,7 @@ Response onRequest(RequestContext context) {
161167
}
162168
```
163169

164-
## Testing 🧪
170+
### Testing 🧪
165171

166172
In Dart Frog, we can unit test our route handlers and middleware effectively because they are just pure functions.
167173

@@ -194,6 +200,8 @@ void main() {
194200

195201
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.
196202

203+
For more information, see the [example][example_link] and our [roadmap][roadmap_link].
204+
197205
## Feature Set ✨
198206

199207
✅ Hot Reload ⚡️
@@ -225,9 +233,12 @@ In the above test, we're using `package:mocktail` to create a mock `RequestConte
225233
[ci_link]: https://github.com/VeryGoodOpenSource/dart_frog/actions/workflows/dart_frog.yaml
226234
[dart_frog_link_dark]: https://github.com/verygoodopensource/dart_frog#gh-dark-mode-only
227235
[dart_frog_link_light]: https://github.com/verygoodopensource/dart_frog#gh-light-mode-only
236+
[example_link]: https://github.com/VeryGoodOpenSource/dart_frog/tree/main/example
228237
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
229238
[license_link]: https://opensource.org/licenses/MIT
230239
[logo_black]: ./assets/dart_frog_logo_black.png#gh-light-mode-only
231240
[logo_white]: ./assets/dart_frog_logo_white.png#gh-dark-mode-only
241+
[roadmap_link]: https://github.com/VeryGoodOpenSource/dart_frog/blob/main/ROADMAP.md
232242
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
233243
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis
244+
[very_good_ventures_link]: https://verygood.ventures

0 commit comments

Comments
 (0)