<commit_before># Remote services

[![Build Status](https://drone.io/github.com/enyo/remote-services/status.png)](https://drone.io/github.com/enyo/remote-services/latest)

A complete abstraction of client <-> server communication


## Usage


### On the server

Define your services:

```dart
class UserService extends Service {
  
  @Route()
  Future<CreateUserResponse> create(Context context, CreateUserRequest request) {
  
  }

}

ServiceDefinitions getServiceDefinitions() {
  return new ServiceDefinitions()
      ..addService(UserService)
      ..addServer(new HttpServiceServer());
}
```

Then in your `/bin/` folder you have a script that calls:

```dart
import "my_services.dart";

getServiceDefinitions().startServers();
```

And in you `build.dart` you set the script to generate the client classes:


```dart
// TODO
```

### On the client


You import the generated classes from the server, and use the services like this:



```dart
import "package:my_server/services.dart" as remote_services;

CreateUserRequest createUserRequest = getMessage();
remote_services.userService.create(createUserRequest);
```




## Advanced configuration

### Context initializers

Every *route* and *route filter* receives a `Context` object that gets
instantiated for every request. If you don't define a `ContextInitializer`
yourself, you will always receive the default `Context` implementation, which
only holds the `ServiceRequest` object.

If you want to have additional information in you context (like session data),<commit_msg>Updated client example.<commit_after># Remote services

[![Build Status](https://drone.io/github.com/enyo/remote-services/status.png)](https://drone.io/github.com/enyo/remote-services/latest)

A complete abstraction of client <-> server communication


## Usage


### On the server

Define your services:

```dart
class UserService extends Service {
  
  @Route()
  Future<CreateUserResponse> create(Context context, CreateUserRequest request) {
  
  }

}

ServiceDefinitions getServiceDefinitions() {
  return new ServiceDefinitions()
      ..addService(UserService)
      ..addServer(new HttpServiceServer());
}
```

Then in your `/bin/` folder you have a script that calls:

```dart
import "my_services.dart";

getServiceDefinitions().startServers();
```

And in you `build.dart` you set the script to generate the client classes:


```dart
// TODO
```

### On the client


You import the generated classes from the server, and use the services like this:


```dart
import "package:remote_services/browser_client.dart";

main() {
  var client = new HttpServiceClient(Uri.parse("http://localhost:8088"));

  var services = new Services(client);

  String email = "<EMAIL>", password = "password";

  services.userService.auth(new AuthenticationRequest()..email=email..password=<PASSWORD>)
      .then((User user) => doSomething(user));

}
```



## Advanced configuration

### Context initializers

Every *route* and *route filter* receives a `Context` object that gets
instantiated for every request. If you don't define a `ContextInitializer`
yourself, you will always receive the default `Context` implementation, which
only holds the `ServiceRequest` object.

If you want to have additional information in you context (like session data),
{'fraction_non_alphanumeric': 0.11321330485199878, 'fraction_numerical': 0.0012206286237412267, 'mean_word_length': 4.8431372549019605, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5763206', 'n_tokens_mistral': 957, 'n_tokens_neox': 897, 'n_words': 308}