Skip to content

Commit a19e68b

Browse files
committed
Add example
1 parent 8c51baf commit a19e68b

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

example/main.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'package:servicestack/client.dart';
2+
import 'test.dtos.dart';
3+
4+
main() async {
5+
var client = new JsonServiceClient("http://test.servicestack.net");
6+
7+
var request = new Hello(name: "World");
8+
HelloResponse response = await client.get(request);
9+
10+
print("Result: ${response.result}");
11+
}

example/test.dtos.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* Options:
2+
Date: 2018-08-09 03:02:31
3+
Version: 5.00
4+
Tip: To override a DTO option, remove "//" prefix before updating
5+
BaseUrl: http://test.servicestack.net
6+
7+
//GlobalNamespace:
8+
//AddServiceStackTypes: True
9+
//AddResponseStatus: False
10+
//AddImplicitVersion:
11+
//AddDescriptionAsComments: True
12+
IncludeTypes: Hello.*
13+
//ExcludeTypes:
14+
//DefaultImports: package:servicestack/client.dart,dart:collection,dart:typed_data
15+
*/
16+
17+
import 'package:servicestack/client.dart';
18+
19+
class HelloResponse implements IConvertible
20+
{
21+
String result;
22+
23+
HelloResponse({this.result});
24+
HelloResponse.fromJson(Map<String, dynamic> json) { fromMap(json); }
25+
26+
fromMap(Map<String, dynamic> json) {
27+
result = json['result'];
28+
return this;
29+
}
30+
31+
Map<String, dynamic> toJson() => {
32+
'result': result
33+
};
34+
35+
TypeContext context = _ctx;
36+
}
37+
38+
// @Route("/hello")
39+
// @Route("/hello/{Name}")
40+
class Hello implements IReturn<HelloResponse>, IConvertible
41+
{
42+
// @Required()
43+
String name;
44+
45+
String title;
46+
47+
Hello({this.name,this.title});
48+
Hello.fromJson(Map<String, dynamic> json) { fromMap(json); }
49+
50+
fromMap(Map<String, dynamic> json) {
51+
name = json['name'];
52+
title = json['title'];
53+
return this;
54+
}
55+
56+
Map<String, dynamic> toJson() => {
57+
'name': name,
58+
'title': title
59+
};
60+
61+
createResponse() { return new HelloResponse(); }
62+
String getTypeName() { return "Hello"; }
63+
TypeContext context = _ctx;
64+
}
65+
66+
TypeContext _ctx = new TypeContext(library: 'test.servicestack.net', types: <String, TypeInfo> {
67+
'HelloResponse': new TypeInfo(TypeOf.Class, create:() => new HelloResponse()),
68+
'Hello': new TypeInfo(TypeOf.Class, create:() => new Hello()),
69+
});

0 commit comments

Comments
 (0)