Monday, May 28, 2012

Use IAPIExplorer To List Your ASP.NET Web APIs


IApiExplorer is a new abstraction layer that allows you to obtain a description of the structure of your ASP.NET Web APIs. This interface also comes with a default implementation - APIExplorer.

IApiExplorer is an abstraction layer that allows you to obtain a description of the structure of your Web APIs. This information can be used to produce documentation, machine-readable metadata, or a test client.

ApiExplorer is the default implementation of IApiExplorer that inspects the routes and other Web API constructs to produce the description.

Some of the things you can do with this API -
Produce Documentation
Create Machine Readable Metadata
Create a Test Client

The main goal of this class is to produce a collection of ApiDescription. It does so by statically inspecting the routes and the available actions inside your controllers. Each ApiDescription describes an API that is available on your service. As you can see from the simplified class diagram below, the ApiDescription contains basic information such as the HttpMethod, the RelativePath, the Documentation, etc. But it also points to an ActionDescriptor which is part of the core Web API component that knows everything about an action. You can use it to access a lot more information such as the action name, the return type, the custom attributes, etc. Similarly, you can access the ParameterDescriptor for the expected parameters.

No comments: