http_sugar 0.0.1 http_sugar: ^0.0.1 copied to clipboard
Sugar methods for HttpRequest and HttpResponse
http_sugar #
Sugar methods for HttpRequest and HttpResponse
Usage #
import 'dart:io';
import 'package:http_sugar/http_sugar.dart';
void main() async {
final server = await HttpServer.bind(InternetAddress.anyIPv4, 3000);
await for (HttpRequest req in server) {
final body = await req.toJson();
switch (body['result']) {
case 'success':
req.response.success();
break;
case 'error':
req.response.error();
break;
case 'notFound':
req.response.notFound();
break;
case 'respondWithJson':
req.response.json({'key': 'value'});
break;
}
}
}
License #
MIT
Author #
Andrei Lesnitsky