AsyncAPI is an open source initiative with as goal to document event-driven architectures in a similar that OpenAPI documents REST APIs. If you want to get a good introduction chec k out my previous posts about AsyncAPI:
- AsyncApi–Share your message contracts in a language agnostic manner - Part 1
- AsyncApi–Share your message contracts in a language agnostic manner - Part 2
Today I want to talk about that allows you to integrate an AsyncAPI more easily into your ASP.NET Core application; Neuroglia AsyncAPI.
Let me walk you through a small example I created.
- First add the following nuget package to your ASP.NET Core project:
- Neuroglia.AsyncApi.AspNetCore.UI
- Now we can register the necessary configuration:
- Notice in the code above that I’m referring to an
OrdersController
class. This ASP.NET core controller publishes an event to create a new order: - The library scans the provided class to find specific attributes to build up the AsyncAPI schema. We also need to register the necessary middleware:
- If we now run the application and browse to the asyncapi endpoint, you can see the AsyncAPI information:
Remark: Be aware that to make this work you need to enable RazorPages (which is not mentioned in the documentation):