Dart-RPC is a package for building server-side RESTful Dart APIs.
A Light-weight RPC package for creating RESTful server-side Dart APIs. The package supports the Google Discovery Document format for message encoding and HTTP REST for routing of requests.
You can choose to use any web server framework you prefer for serving HTTP requests. The rpc-examples github repository (https://github.com/dart-lang/rpc-examples) includes examples for both the standard dart:io
HttpServer as well as an example using the shelf
middleware.
Simple Example
@ApiClass(version: 'v1')
class Cloud {
@ApiMethod(method: 'GET', path: 'resource/{name}')
ResourceMessage getResource(String name) {
return new ResourceMessage()
..id = 1
..name = "example_resource"
..capacity = 123;
}
@ApiMethod(method: 'POST', path: 'resource/{name}/update')
VoidMessage updateResource(String name, UpdateMessage request) {
// ... process request, throw on error ...
}
}
class ResourceMessage {
int id;
String name;
int capacity;
}
class UpdateMessage {
int newCapacity;
}
Find out more in the github repository