What you need for this tutorial

Get Full Streamy

Can't I just get it from pub?

Yes, and no. You can and should use pub to import Streamy runtime library necessary to run your app. However, Streamy comes with command-line tools to work with Discovery files and generate API client libraries, so you need to download the full version.

Get a Discovery file

Find one for the API you want to access. Let's use Google URL shortener as example:

Generate client library

What just happened?

The apigen.dart program provided by Streamy reads the discovery file (urlshortener.json in the example) and produces a Dart file (urlshortener.dart in the example) that contains an API client library for the API described in the discovery file. You can also give the library your own custom name (urlshortener in the example).

Use it

Let's create an entry point for our program, called main.dart, which contains the following code:

What just happened?

import 'urlshortener.dart';

This line imports the API client library that we just generated from the discovery file.

import 'package:streamy/impl_server.dart';

This import provides an implementation of Streamy's RequestHandler interface. This particular implementation works for server-side and command-line apps. If your app runs in the web-browser, use package:streamy/impl_html.dart and HtmlRequestHandler instead.

The above two lines instantiate a Urlshortener API client backed by ServerRequestHandler.

api.url.insert(new Url()..longUrl = args[0])

This is an example of how you create an API request. Streamy API generator generates a fully type-annotated root API class (Urlshortener), resources (url), resource methods (insert), entity classes (Url) as well as getters/setters for properties on the entities (longUrl), so you can use auto-completion in your IDE and rely on compiler warnings to tell you about issues in your usage of the API.