Using Microsoft Kiota to create a client
Running the API service generating the OpenAPI document (this was done in Chapter 2), we can leverage this information, and create the client code automatically. With the sample code of this chapter, the OpenAPI document is stored with the file gamesapi-swagger.json
, which you can reference without starting the service.
One option with Visual Studio is to use Add | Connected Client and add a service reference to an OpenAPI document. But this option (at the time of this writing) has some limitations:
- It still uses the Newtonsoft Json serializer, whereas the new
System.Text.Json
one is faster and uses less memory - The client implementation makes use of strings instead of streams, which can result in objects in the large object heap
As you’ve seen in this chapter, creating a custom library to create HTTP requests is not that hard and can be optimized for your own domain.
But now there’s another option that...