Create your own REST API with Dart

2,539 views
Skip to first unread message

Gustav Wibling

unread,
Mar 24, 2015, 7:28:54 AM3/24/15
to cl...@dartlang.org
Hi all,

In case you haven't already noticed there is a new package for writing REST APIs in Dart. If you are interested take a look at the recent blog post,


Cheers,
/gustav

Cristian Garcia

unread,
Mar 24, 2015, 10:36:25 AM3/24/15
to Gustav Wibling, cl...@dartlang.org
Nice!

But I wonder why didn't the Dart team just fork Redstone? The style of both frameworks is awfully similar, I might say that they took some features straight out of Redstone but I couldn't know for sure. From Redstone's perspective they are still missing a bunch of features, but their off in a good direction; I hope they include good DI for testing, and maybe get some way to integrate a couple of existing DB drivers.

Its a project worth watching, but for now Redstone is more complete.

Gustav Wibling

unread,
Mar 26, 2015, 11:48:27 AM3/26/15
to Cristian Garcia, cl...@dartlang.org
Hi Christian,

I can see how the Redstone framework does look similar. However the RPC package was actually inspired by the Google Cloud Endpoints, https://cloud.google.com/endpoints, framework for python, java, etc.

We wanted to have a similar model where a developer could easily write a REST API and not have to worry about routing the request or serializing data between the wire format and the method parameters, except we wanted it to work in general and not just Google AppEngine.

One thing where the RPC package differs from Redstone is the automatic serialization of class to the wire format and back. E.g. you can define a normal Dart class and use it as a parameter to your method and it will automatically be serialized to the network wire format and back to a Dart class.

Another key difference between the RPC package and Redstone is the RPC package's support for providing a Discovery Document which is used to generate a client stub library in a variety of languages. This makes it very easy to create a client calling the server APIs, see https://github.com/dart-lang/rpc#calling-the-api,  since there is no need to serialize data on the client side or create HTTP request using the correct URLs etc. It is all automatically generated.
You can find more information about the Discovery Document format at https://developers.google.com/discovery/v1/reference/apis. It is basically an IDL using JSON that is being used by most (if not all) of Google's public APIs. The RPC package makes it simple to create an API giving the same experience as the standard Google APIs.

I can see that there is an overlap with Redstone. There is also an overlap with Shelf, but to a large degree I see the packages as complementary. E.g. we have an example where we use Shelf to listen for requests and then forward the requests to the RPC package for further routing and deserialization at https://github.com/dart-lang/rpc/blob/master/example/shelf_sample.dart.

Btw. it would be great if you would post your requests/ideas for improvements on the https://github.com/dart-lang/rpc/issues page.

Cheers,
/gustav

Austin Cummings

unread,
Mar 27, 2015, 1:18:03 PM3/27/15
to cl...@dartlang.org, cgarc...@gmail.com
One thing where the RPC package differs from Redstone is the automatic serialization of class to the wire format and back. E.g. you can define a normal Dart class and use it as a parameter to your method and it will automatically be serialized to the network wire format and back to a Dart class.

Redstone actually has a plugin that supports this. redstone_mapper 

Warren Strange

unread,
Mar 29, 2015, 12:04:20 PM3/29/15
to cl...@dartlang.org

How does one hook in authorization into this framework?

For example, if calling a method requires the client to present an access token with a certain OAuth scope ?

I see the google discovery doc format seems to support OAuth scopes in the descriptor. 

I suppose one could use some shelf middleware before the API handler- but this seems pretty kludgy in that you would need to be making path decisions in two places.  

Warren Strange

unread,
Mar 31, 2015, 9:20:06 PM3/31/15
to cl...@dartlang.org
Reply all
Reply to author
Forward
0 new messages