Aqueduct에서 서버 측 Dart를 사용해보십시오.
5219 단어 Dart
준비
Dart 설치
$ brew tap dart-lang/dart
$ brew install dart
참고 htps : //이다 rt. 에서 v / 게 t-rt
Aqueduct 설치
$ pub global activate aqueduct
$ export PATH="$PATH":"$HOME/.pub-cache/bin" # shellファイルに追加
프로젝트 만들기
$ aqueduct create my_project
튜토리얼
자습서 프로젝트 만들기
$ aqueduct create heroes
영웅 목록의 끝점
lib/controller/heroes_controller.dart 만들기
import 'package:aqueduct/aqueduct.dart';
import 'package:heroes/heroes.dart';
class HeroesController extends Controller {
final _heroes = [
{'id': 11, 'name': 'Mr. Nice'},
{'id': 12, 'name': 'Narco'},
{'id': 13, 'name': 'Bombasto'},
{'id': 14, 'name': 'Celeritas'},
{'id': 15, 'name': 'Magneta'},
];
@override
Future<RequestOrResponse> handle(Request request) async {
return Response.ok(_heroes);
}
}
lib/channel.dart 수정
import 'heroes.dart';
+ import 'controller/heroes_controller.dart';
/// This type initializes an application.
///
/// Override methods in this class to set up routes and initialize services like
/// database connections. See http://aqueduct.io/docs/http/channel/.
class HeroesChannel extends ApplicationChannel {
/// Initialize services in this method.
///
/// Implement this method to initialize services, read values from [options]
/// and any other initialization required before constructing [entryPoint].
///
/// This method is invoked prior to [entryPoint] being accessed.
@override
Future prepare() async {
logger.onRecord.listen((rec) => print("$rec ${rec.error ?? ""} ${rec.stackTrace ?? ""}"));
}
/// Construct the request channel.
///
/// Return an instance of some [Controller] that will be the initial receiver
/// of all [Request]s.
///
/// This method is invoked after [prepare].
@override
Controller get entryPoint {
final router = Router();
+
+ router
+ .route('/heroes')
+ .link(() => HeroesController());
// Prefer to use `link` instead of `linkFunction`.
// See: https://aqueduct.io/docs/http/request_controller/
router
.route("/example")
.linkFunction((request) async {
return Response.ok({"key": "value"});
});
return router;
}
}
서버 시작
$ aqueduct serve
http://localhost:8888/heroes 에서 결과를 볼 수 있습니다.
Reference
이 문제에 관하여(Aqueduct에서 서버 측 Dart를 사용해보십시오.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kei4eva4/items/4dd02c453d49bad48bcf
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
$ brew tap dart-lang/dart
$ brew install dart
$ pub global activate aqueduct
$ export PATH="$PATH":"$HOME/.pub-cache/bin" # shellファイルに追加
$ aqueduct create my_project
자습서 프로젝트 만들기
$ aqueduct create heroes
영웅 목록의 끝점
lib/controller/heroes_controller.dart 만들기
import 'package:aqueduct/aqueduct.dart';
import 'package:heroes/heroes.dart';
class HeroesController extends Controller {
final _heroes = [
{'id': 11, 'name': 'Mr. Nice'},
{'id': 12, 'name': 'Narco'},
{'id': 13, 'name': 'Bombasto'},
{'id': 14, 'name': 'Celeritas'},
{'id': 15, 'name': 'Magneta'},
];
@override
Future<RequestOrResponse> handle(Request request) async {
return Response.ok(_heroes);
}
}
lib/channel.dart 수정
import 'heroes.dart';
+ import 'controller/heroes_controller.dart';
/// This type initializes an application.
///
/// Override methods in this class to set up routes and initialize services like
/// database connections. See http://aqueduct.io/docs/http/channel/.
class HeroesChannel extends ApplicationChannel {
/// Initialize services in this method.
///
/// Implement this method to initialize services, read values from [options]
/// and any other initialization required before constructing [entryPoint].
///
/// This method is invoked prior to [entryPoint] being accessed.
@override
Future prepare() async {
logger.onRecord.listen((rec) => print("$rec ${rec.error ?? ""} ${rec.stackTrace ?? ""}"));
}
/// Construct the request channel.
///
/// Return an instance of some [Controller] that will be the initial receiver
/// of all [Request]s.
///
/// This method is invoked after [prepare].
@override
Controller get entryPoint {
final router = Router();
+
+ router
+ .route('/heroes')
+ .link(() => HeroesController());
// Prefer to use `link` instead of `linkFunction`.
// See: https://aqueduct.io/docs/http/request_controller/
router
.route("/example")
.linkFunction((request) async {
return Response.ok({"key": "value"});
});
return router;
}
}
서버 시작
$ aqueduct serve
http://localhost:8888/heroes 에서 결과를 볼 수 있습니다.
Reference
이 문제에 관하여(Aqueduct에서 서버 측 Dart를 사용해보십시오.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kei4eva4/items/4dd02c453d49bad48bcf
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import 'package:aqueduct/aqueduct.dart';
import 'package:heroes/heroes.dart';
class HeroesController extends Controller {
final _heroes = [
{'id': 11, 'name': 'Mr. Nice'},
{'id': 12, 'name': 'Narco'},
{'id': 13, 'name': 'Bombasto'},
{'id': 14, 'name': 'Celeritas'},
{'id': 15, 'name': 'Magneta'},
];
@override
Future<RequestOrResponse> handle(Request request) async {
return Response.ok(_heroes);
}
}
import 'heroes.dart';
+ import 'controller/heroes_controller.dart';
/// This type initializes an application.
///
/// Override methods in this class to set up routes and initialize services like
/// database connections. See http://aqueduct.io/docs/http/channel/.
class HeroesChannel extends ApplicationChannel {
/// Initialize services in this method.
///
/// Implement this method to initialize services, read values from [options]
/// and any other initialization required before constructing [entryPoint].
///
/// This method is invoked prior to [entryPoint] being accessed.
@override
Future prepare() async {
logger.onRecord.listen((rec) => print("$rec ${rec.error ?? ""} ${rec.stackTrace ?? ""}"));
}
/// Construct the request channel.
///
/// Return an instance of some [Controller] that will be the initial receiver
/// of all [Request]s.
///
/// This method is invoked after [prepare].
@override
Controller get entryPoint {
final router = Router();
+
+ router
+ .route('/heroes')
+ .link(() => HeroesController());
// Prefer to use `link` instead of `linkFunction`.
// See: https://aqueduct.io/docs/http/request_controller/
router
.route("/example")
.linkFunction((request) async {
return Response.ok({"key": "value"});
});
return router;
}
}
$ aqueduct serve
Reference
이 문제에 관하여(Aqueduct에서 서버 측 Dart를 사용해보십시오.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kei4eva4/items/4dd02c453d49bad48bcf텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)