One of the cool features of F# are Type Providers. Type providers provide an information-rich programming model where type information(types, properties, methods,…) can be deferred form internal and external information sources. For example, an F# type provider for SQL will provide the types, properties, and methods you need to work directly with the tables of any SQL database you have access to. Similarly, a type provider for WSDL web services will provide the types, properties, and methods you need to work directly with any WSDL web service.
Last week I discovered a Type Provider for Swagger(a simple yet powerful representation of your RESTful API) called SwaggerProvider.
Let’s see SwaggerProvider in action:
- Create a new F# application
- Add an F# code file
- Add the SwaggerProvider NuGet package to your project
- Load the provider in your module, specify the location of the swagger.json schema information and create a provider instance:
- If we now access the petStore instance, we’ll get a list of available methods deferred from the swagger metadata:
Consuming a Web API was never so easy!