Created
January 20, 2025 16:37
-
-
Save maisarissi/f01b8d5222f44fba16c478cfd1bb03e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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