You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+146-2Lines changed: 146 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ To make API calls we need to use the `JsonServiceClient`, installed by adding th
29
29
30
30
```yaml
31
31
dependencies:
32
-
servicestack: ^1.0.4
32
+
servicestack: ^1.0.5
33
33
```
34
34
35
35
Saving `pubspec.yaml` in VS Code with the [Dart Code Extension](https://dartcode.org) automatically calls `pub get` or `flutter packages get` (in Flutter projects) to add any new dependencies to your project.
@@ -51,6 +51,30 @@ main() async {
51
51
52
52
Like C#, Dart has Generics and Type Inference so the `response` returned is the typed `HelloResponse` DTO giving us rich intelli-sense and compiler type safety.
53
53
54
+
### JsonWebClient
55
+
56
+
For browser projects you would instead use the `JsonWebClient` from `web_client.dart`, e.g:
57
+
58
+
```dart
59
+
import 'package:servicestack/web_client.dart';
60
+
61
+
var client = new JsonWebClient("https://www.techstacks.io");
62
+
```
63
+
64
+
The `JsonWebClient` performs HTTP Requests using [dart:html BrowserClient](https://webdev.dartlang.org/angular/guide/server-communication) to use the browsers built-in `XMLHttpRequest` object. Despite their implementation differences `JsonWebClient` also supports the same feature-set as the Dart VM's `JsonServiceClient` above.
65
+
66
+
#### Concrete-specific functionality
67
+
68
+
In addition to implementing the `IServiceClient` above, each Service Client includes additional concrete specific functionality allowing for finer-grained access to their underlying HTTP Clients, e.g. as the Request/Response filters have different Type signatures (dart:io's `HttpClientResponse` vs Browser's `Response`) they can't be declared in the shared `IServiceClient` interface, but thanks to Dart's type inference many of the extended concrete APIs are still source-compatible, e.g:
Thanks to the direct C# to Dart model code generation we're able to create the ideal idiomatic message-based APIs utilizing rich typed models with broad support for many of the C#/.NET features used when defining DTOs inc. Generics, Inheritance, multiple Interfaces, Enums (inc. int and Flag Enums), Tuples, metadata Attributes emitted in comments (emitting additional documentation in the generated models) whilst also taking care of mapping built-in C# Types like `DateTime`, `TimeSpan`, `byte[]` and `Stream` into their equivalent native Dart [DateTime](https://api.dartlang.org/stable/1.24.3/dart-core/DateTime-class.html), [Duration](https://api.dartlang.org/stable/1.24.3/dart-core/Duration-class.html) and [Uint8List](https://api.dartlang.org/stable/1.24.3/dart-typed_data/Uint8List-class.html) types, C# generic collections are also converted into their equivalent Dart generic collection Type.
@@ -183,7 +207,7 @@ Then to use `JsonServiceClient` add the `servicestack` dependency to your apps [
183
207
184
208
```yaml
185
209
dependencies:
186
-
servicestack: ^1.0.4
210
+
servicestack: ^1.0.5
187
211
```
188
212
189
213
Saving `pubspec.yaml` automatically runs [flutter packages get](https://flutter.io/using-packages/) to install any new dependencies in your App.
@@ -467,6 +491,126 @@ To display the image we assign the response to the `imageBytes` field within the
The [HelloAngularDart](https://github.com/ServiceStackApps/HelloAngularDart) project demonstrates the same functionality in an AngularDart Web App running inside a Web Browser.
497
+
498
+
The only difference is having to import `servicestack/web_client.dart` containing the `JsonWebClient`:
499
+
500
+
```dart
501
+
import 'package:servicestack/web_client.dart';
502
+
```
503
+
504
+
and changing the clients to use the `JsonWebClient` instead, e.g:
505
+
506
+
```dart
507
+
var testClient = new JsonWebClient(TestBaseUrl);
508
+
var techstacksClient = new JsonWebClient(TechStacksBaseUrl);
509
+
```
510
+
511
+
But otherwise the actual client source code for all of the Typed API requests remains exactly the same.
512
+
513
+
The `HelloAngularDart` App is contained within the [hello_world](https://github.com/ServiceStackApps/HelloAngularDart/tree/master/lib/src/hello_world) component with all Dart logic in:
0 commit comments