api_agent 0.2.0 copy "api_agent: ^0.2.0" to clipboard
api_agent: ^0.2.0 copied to clipboard

outdated

Generate technology-agnostic api bindings for both client and server.

example/lib/main.dart

// Shared api definitions

import 'package:api_agent/api_agent.dart';

@ApiDefinition()
abstract class GreetApi {
  Future<String> greet(String name);
}

// On the client

import 'package:api_agent/clients/http_client.dart';

Future<void> clientMain() async {
  var client = GreetApiClient(
    HttpApiClient(domain: 'http://localhost:8080'),
  );

  var result = await client.greet('James');
  print(result); // prints 'Hello James.';
}

// On the server

import 'package:api_agent/servers/shelf_router.dart';
import 'package:shelf/shelf_io.dart';

void serverMain() async {
  var api = ShelfApiRouter([
    GreetApiEndpoint.from(
      greet: GreetEndpoint.from((name, _) {
        return 'Hello $name.';
      }),
    ),
  ]);

  serve(api, InternetAddress.anyIPv4, 8080);
}
6
likes
0
points
65
downloads

Publisher

verified publisherschultek.dev

Weekly Downloads

Generate technology-agnostic api bindings for both client and server.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, build, collection, dart_style, http, path, shelf, shelf_router, source_gen

More

Packages that depend on api_agent