Skip to content

Instantly share code, notes, and snippets.

@maisarissi
Created January 20, 2025 16:37
Show Gist options
  • Save maisarissi/f01b8d5222f44fba16c478cfd1bb03e8 to your computer and use it in GitHub Desktop.
Save maisarissi/f01b8d5222f44fba16c478cfd1bb03e8 to your computer and use it in GitHub Desktop.
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}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment