Skip to content

Commit 8cc4f4f

Browse files
authored
docs(README): add status code, json, and fun facts (#55)
1 parent 8ef4567 commit 8cc4f4f

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ dart_frog build
6060

6161
Dart Frog is built on top of [shelf](https://pub.dev/packages/shelf) and [mason](https://pub.dev/packages/mason) and is inspired by many tools including [remix.run](https://remix.run), [next.js](https://nextjs.org), and [express.js](https://expressjs.com).
6262

63-
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!
63+
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.
64+
65+
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!
6466

6567
## Feature Set ✨
6668

@@ -118,6 +120,28 @@ Response onRequest(RequestContext context) {
118120
}
119121
```
120122

123+
We can customize the status code of the response via the `statusCode` parameter on the `Response` object:
124+
125+
```dart
126+
import 'package:dart_frog/dart_frog.dart';
127+
128+
Response onRequest(RequestContext context) {
129+
return Response(statusCode: 204);
130+
}
131+
```
132+
133+
In addition, we can return JSON via the `Response.json` constructor:
134+
135+
```dart
136+
import 'package:dart_frog/dart_frog.dart';
137+
138+
Response onRequest(RequestContext context) {
139+
return Response.json(
140+
body: <String, dynamic>{'hello': 'world!'},
141+
);
142+
}
143+
```
144+
121145
Route handlers can be synchronous or asynchronous. To convert the above route handlers to async, we just need to update the return type from `Response` to `Future<Response>`. We can add the `async` keyword in order to `await` futures within our handler before returning a `Response`.
122146

123147
```dart
@@ -239,8 +263,14 @@ void main() {
239263

240264
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.
241265

266+
### Additional Resources 📚
267+
242268
For more information, see the [example][example_link] and our [roadmap][roadmap_link].
243269

270+
*💡 Fun Fact: the [dart2js][dart2js_compiler_link] compiler [used to be called frog][dart2js_frog_pr_link].*
271+
272+
[dart2js_compiler_link]: https://dart.dev/tools/dart2js
273+
[dart2js_frog_pr_link]: https://github.com/dart-lang/sdk/issues/2194
244274
[dart_installation_link]: https://dart.dev/get-dart
245275
[ci_badge]: https://github.com/VeryGoodOpenSource/dart_frog/actions/workflows/dart_frog.yaml/badge.svg
246276
[ci_link]: https://github.com/VeryGoodOpenSource/dart_frog/actions/workflows/dart_frog.yaml

0 commit comments

Comments
 (0)