Skip to content

The AsyncAPI.NET SDK contains a useful object model for AsyncAPI documents in .NET

License

Notifications You must be signed in to change notification settings

ylmzertg/AsyncAPI.NET

 
 

Repository files navigation

AsyncAPI.NET

Build & Test

The AsyncAPI.NET SDK contains a useful object model for the AsyncAPI specification in .NET along with common serializers to extract raw AsyncAPI JSON and YAML documents from the model as well.

Installation

Install the NuGet packages:

Example Usage

Main classes to know:

  • AsyncApiStringReader
  • AsyncApiStringWriter
    • There is an extension on the AsyncApiDocument type which allows Serializing as well (new AsyncApiDocument().SerializeAsJson() or new AsyncApiDocument().SerializeAsYaml()

Writing

var myFirstAsyncApi = new AsyncApiDocument
{
  Info = new AsyncApiInfo
  {
    Title = "my first asyncapi"
  },
  Channels = new Dictionary<string, AsyncApiChannel>
  {
    {
	"users", new AsyncApiChannel
	{
	    Subscribe = new AsyncApiOperation
	    {
		OperationId = "users",
		Description = "my users channel"
	    }
	}
    }
  }
};
var yaml = myFirstAsyncApi.SerializeAsYaml();
//asyncapi: '2.5.0'
//  info:
//    title: my first asyncapi
//  channels:
//    users:
//      subscribe:
//        operationId: users
//        description: my users channel

Reading

var httpClient = new HttpClient
{
  BaseAddress = new Uri("https://raw.githubusercontent.com/asyncapi/spec/"),
};

var stream = await httpClient.GetStreamAsync("master/examples/streetlights-kafka.yml");
var asyncApiDocument = new AsyncApiStreamReader().Read(stream, out var diagnostic);

Attribution

Contribution

This project welcomes contributions and suggestions. Do you want to contribute to the project? Find out how here.

License

Modified Apache 2.0 (Section 6)

About

The AsyncAPI.NET SDK contains a useful object model for AsyncAPI documents in .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.9%
  • JavaScript 0.1%