Questions tagged [dart-rpc]

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

10 questions
2
votes
1 answer

How do you handle query parameters of the form "hub.challenge" in dart lang using RPC?

Typically query parameters get mapped to optional variables in dart lang using rpc. For example http://www.exampleurl.com/test?filter=1 Future test({int filter}) Gets mapped to filter. However if it is…
2
votes
1 answer

How to get the client IP in a dart shelf-rpc server

I have a dart web service application written with Shelf and Rpc apis. I need to check the client Ip inside my api methods, but I cannot figure how. The context method does not contain the HttpRequest .contentInfo property. More, also the shelf…
J F
  • 1,058
  • 2
  • 10
  • 21
2
votes
1 answer

Dart-RPC: Use Protocol Buffers serialisation instead of JSON

Be default, Dart-RPC uses JSON serialisation when transferring objects (class instances) between the server and the client. How can I use Protobuf (Protocol Buffers) serialisation instead? Is it possible to specify the serialisation method (like a…
Alon Amir
  • 4,913
  • 9
  • 47
  • 86
2
votes
1 answer

Dart await keyword

I want to try the rpc package of Dart using the io sample (https://github.com/dart-lang/rpc) I'm on the 64 bits version of Dart editor with the 1.9.1 sdk (cannot update more thans stable version) This is my pubspec.yaml : name:…
Electron
  • 85
  • 7
1
vote
2 answers

Dart RPC and object hierarchies

This is probably a really basic question about REST APIs. I just started reading the docs and don't see how to implement an API for an object/model that has sub-objects. Instead there is only a description of objects with primitives only (int,…
Tom Russell
  • 1,015
  • 2
  • 10
  • 29
1
vote
1 answer

Dart - error running rpc generate client

I am trying to follow the "Beware the Nest o’ Pirates" tutorial https://www.dartlang.org/codelabs/server/ and have hit a problem when I try to generate the client code for the PiratesApi When I run the command pub global run rpc:generate client -i…
richard
  • 2,887
  • 5
  • 26
  • 36
1
vote
1 answer

Using Document Discovery service on a non-app engine service

I have been playing around with the RPC package in Dart which makes it easy to add a Document Discovery service to Dart server. After a bit of Googling I found out about the API Discovery Service https://developers.google.com/discovery/ which…
richard
  • 2,887
  • 5
  • 26
  • 36
1
vote
1 answer

incompatibility when running dart rpc and shelf (with shelf_rpc) related to headers which are lists (and not Strings)

incompatibility when running dart rpc and shelf (with shelf_rpc) related to headers which are lists (and not Strings). It seems that there is an incompatibility when running dart rpc and shelf (with shelf_rpc) related to headers which are lists…
Benjamin
  • 275
  • 2
  • 8
1
vote
1 answer

Incompatibility between the Dart shelf and rpc packages? ('access-control-request-method' header)

There seems to be an incompatibility between the shelf and rpc packages. In rpc [0.4.1] config/api.dart: The handleHttpOptionsRequest expects the 'access-control-request-method' header to be a List: Future
Benjamin
  • 275
  • 2
  • 8
0
votes
2 answers

Dart RPC API Method using async

Using dart rpc can you label a API method as "async"? I see in the documentation you can return a future, but when I try to label the method async it seems to create a lot of problems.