API client generator: Microsoft Kiota learns how to use Dart

The API client generator Kiota can now handle Dart on an experimental basis. Support is already stable for C#, Go, Java and other programming languages.

listen Print view

(Image: TierneyMJ / Shutterstock.com)

2 min. read

Microsoft has announced that Kiota has now received experimental support for the Dart programming language as a public preview. Kiota is a client generator for APIs described by OpenAPI. Kiota API clients are intended to offer the advantage of strong typing and free developers from having to learn a new library for each HTTP API.

Videos by heise

Kiota already offers support for other programming languages such as C#, Go, Java, PHP, Python, Ruby, and TypeScript –, some of which are still experimental or preview features. Experimental support for Dart is now on board as a community-driven innovation. Dart is an ECMA-standardized programming language developed by Google with a focus on cross-platform applications and is used, for example, in the cross-platform framework Flutter from the same company.

Kiota can be installed in different ways – for example as an extension for Visual Studio Code, as has been possible since 2023, in a Docker container or as a .NET tool. After going through the next necessary steps, which Microsoft describes in a guide, Dart – experimental is available as a selection option when creating a new API client. As soon as this is available, it can be used in a Dart application. An example of how the API can then be called using the API key can be found in the instructions:

import '../client/posts_client.dart';
import '../client/models/post.dart';
import 'package:microsoft_kiota_bundle/microsoft_kiota_bundle.dart';
import 'package:microsoft_kiota_abstractions/microsoft_kiota_abstractions.dart';

void main(List<String> arguments) async {
  var authenticationProvider = AnonymousAuthenticationProvider();
  var requestAdapter =
      DefaultRequestAdapter(authProvider: authenticationProvider);
  var client = PostsClient(requestAdapter);

  // GET /posts/{id}
  var specificPostId = 5;
  var specificPost = await client.posts.byPostId(specificPostId).getAsync();
  print(
      'Retrieved post - ID: ${specificPost?.id}, Title: ${specificPost?.title}, Body: ${specificPost?.body}');

  // POST /posts
  var newPost = Post();
  newPost.body = 'Hello world';
  newPost.title = 'Testing Kiota-generated API client';
  newPost.userId = 42;
  var createdPost = await client.posts.postAsync(newPost);
  print('Created new post with ID: ${createdPost?.id}');
}

As Microsoft emphasizes, user feedback is not only valuable at this stage, but also when Dart support will be generally available in Kiota. Iterative improvements should then contribute to robust support.

All further information on the new Dart support can be found on Microsoft's developer blog. The Kiota documentation provides further details on the API client generator.

(mai)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.