Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/helightdev/catwalk
https://github.com/helightdev/catwalk
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/helightdev/catwalk
- Owner: helightdev
- License: other
- Created: 2024-05-31T10:02:25.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-06-12T13:02:20.000Z (5 months ago)
- Last Synced: 2024-06-12T18:48:35.729Z (5 months ago)
- Language: Dart
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Example
## Shared Library Content
```dart
// Create a protocol instance that should be used by this endpoint.
// This contains serializers and the transport format that should be used.
final protocol = JsonRpcProtocol();// Create an endpoint interface that will be implemented by both the client and server.
@EndpointMacro()
abstract interface class TestEndpoint implements Endpoint {
Future getName(String userId);Future nullableString();
}
```## Server
```dart
// Create a simple rpc server that uses the TestController to handle requests.
void main(List arguments) async {
var server = JsonRpcServer(protocol, TestController(), TestEndpoint.routes);
await server.serve();
}// The server sided implementation of the TestEndpoint.
class TestController implements TestEndpoint {@override
Future getName(String userId) {
return Future.value("Answer: $userId");
}@override
Future nullableString() {
return Future.value(null);
}
}
```## Client
```dart
// Access the server using the TestEndpointClient.
void main(List arguments) async {
protocol.client = JsonRpcClient(JsonRpcClientConfig(baseUrl: "http://localhost:8080"));
var client = TestEndpointClient(protocol);
print(await client.getName("Moin!"));
}@ClientMacro()
class TestEndpointClient implements TestEndpoint {}
```