-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExample.dart
More file actions
103 lines (81 loc) · 2.68 KB
/
Example.dart
File metadata and controls
103 lines (81 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env dart
import '../lib/json_client.dart';
import 'dart:io';
import "dart:async";
JsonClient newClient(String url) =>
new JsonClient(url)
..logLevel = LogLevel.Error;
Do_Rockstars(){
var client = newClient("http://razor.servicestack.net/");
client.rockstars
.then(print);
client.rockstars()
.then(print);
client.rockstars(1)
.then(print);
}
Do_Northwind(){
print("Do_Northwind(): ");
var client = newClient("http://mono.servicestack.net/ServiceStack.Northwind");
client.customers()
.then((response) {
var mexicanNames = response['Customers']
.where((x) => x['Country'] == "Mexico")
.map((x) => x['ContactName'])
.toList();
print("Mexican Customers: $mexicanNames");
});
}
Do_RestFiles(){
print("Do_RestFiles(): ");
var client = newClient("http://mono.servicestack.net/RestFiles");
client.files
.then((r) => print("GET response: ${r}"));
client.files("dtos/Operations/RevertFiles.cs.txt")
.then((r) => print("GET response: $r"));
client.get('files/Global.asax.cs.txt')
.then((r) => print("Global.asax:\n\n${r['File']['Contents']}"));
int nowMs = (new DateTime.now()).millisecondsSinceEpoch;
client.files({'path':'newFolder$nowMs'}, (r) => print("POST response: ${r}") );
client.files('?path=services', (r) => print("GET response: ${r}") );
client.get('files?path=services')
.then((r) => print("GET response: ${r}"));
print("Testing error handler on invalid requests...");
client.post('files?forDownload=1BrokenRequest')
.catchError((e) => print("POST error response: ${e}"));
}
Do_BackboneTodos(){
print("Do_BackboneTodos(): ");
var client = newClient("http://mono.servicestack.net/Backbone.Todos/");
List todos = [
'Learn Dart!',
'Clear all existing todo items',
'Add all these todos',
'Mark this todo as done',
'do ALL THE THINGS!'
];
final String completeTodo = 'Mark this todo as done';
markTodoCompleted(List createdTodos) {
List matchingTodos = createdTodos.where((x) => x['content'] == completeTodo).toList();
var todo = matchingTodos[0];
todo['done'] = true;
client.put("todos/${todo['id']}", todo);
}
client.todos()
.then((List existingTodos){
Future.wait(existingTodos.map((x) => client.delete('todos/${x['id']}')) )
.then((_) {
int i=0;
Future.wait( todos.map((text) => client.todos({'content':text, 'order':i++})) )
.then( markTodoCompleted );
});
});
}
void main() {
print("Running JsonClient Examples...\n");
Do_Rockstars();
Do_RestFiles();
Do_Northwind();
Do_BackboneTodos();
print("\nDone!");
}