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
Copy file name to clipboardExpand all lines: README.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,9 @@ dart_frog build
60
60
61
61
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).
62
62
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!
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
+
121
145
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`.
122
146
123
147
```dart
@@ -239,8 +263,14 @@ void main() {
239
263
240
264
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.
241
265
266
+
### Additional Resources 📚
267
+
242
268
For more information, see the [example][example_link] and our [roadmap][roadmap_link].
243
269
270
+
*💡 Fun Fact: the [dart2js][dart2js_compiler_link] compiler [used to be called frog][dart2js_frog_pr_link].*
0 commit comments