Skip to content

Commit

Permalink
Merge pull request #68 from rosera/rosera-patch-1
Browse files Browse the repository at this point in the history
Create ex13-6.md
  • Loading branch information
rosera authored Dec 6, 2022
2 parents caba0e1 + 8db0028 commit 537eba4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ch13/ex13-6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 13.6 Backend HTTP Server
## Example: HTTP Server
```dart
import 'dart:convert';
import 'dart:io';
const port = 8080;
Future<void> main(List<String> arguments) async {
final httpServer = await createHTTPServer();
await httpRequest(httpServer);
}
Future<HttpServer> createHTTPServer() async {
final intAddress = InternetAddress.anyIPv4;
return await HttpServer.bind(intAddress, port);
}
Future<void> httpRequest(HttpServer server) async {
await for (HttpRequest request in server) {
if (request.method == 'GET'){
request.response
..write(' { "data": [ {"title": "January"}, {"title:": "February"}, {"title": "March"} ] }\n')
..close();
}
}
}
```

0 comments on commit 537eba4

Please sign in to comment.