Getting Started
Privacy Assurance: Your Postman collections never leave your computer. This tool operates with Blazor WebAssembly (Wasm), a framework that allows it to run entirely in your browser without making any network calls or sharing information about your collections. Your data stays on your machine.
Have a collection in another format? Postman supports a variety of type and specification for importing. OpenAPI, GraphQL, cURL, RAML, HAR and more are all supported. For more information, visit their page: Supported API definitions formats The imports are well written and create a well-structured collection. If you have a collection in one of these formats, you can import it into Postman and then follow the directions below.
On This Page
Postman2CSharp is a free online tool that allows you to convert Postman Collections into fully featured CSharp ApiClients all in the browser. It has tons of configurations that will let you tailor your ApiClient to your needs. Generated ApiClients come working right out of the box and contain no third party dependencies (unless you choose to add them).
Postman's built in snippet generation does exactly what it's name implies, it generates snippets. It does not generate fully featured ApiClients. It's night and day from Postman2CSharp. It's the difference between generating 10 lines of code and 100,000 lines of code.
Postman2CSharp also posses a lot of functionality that Postman's built in snippet generator does not support. For example, Postman2CSharp generates classes for your query parameters, form data, requests, and responses. Also, since it is generating code for every request instead of just 1 request it is able to determine shared headers, base url, variables, and more to keep your code DRY.
I recently had the opportunity to use Postman2CSharp to generate an ApiClient for an integration with a third party vendor on an enterprise level project. The collection wasn't very large, only 15 or so requests with api-key authentication.
The generated ApiClient came working perfectly. It enabled me to get the integration up and running in a matter of hours instead of days. I was stoked to say the least, all the hours I had put into Postman2CSharp had paid off. Well not yet. It will be fully paid off once I am able to save you time too.The greatest value Postman2CSharp has to offer is it's class deduping. Postman2CSharp will look at all the json in your requests and responses and determine what json examples represent the same class. This process has been very finely tuned and will result in fewer classes generated than even a human could do. This feature can save you a ton of work depending on the collection size.
Step 1: Open Postman and hover over the collection (root folder) you want to export. Click on the ellipsis (...), scroll down, and then select 'Export'.
Step 2: In the 'Export Collection' dialog box, select version 'Collection v2.1'.
Step 3: Click 'Export' and choose the location where you want to save the file.
Step 4: Now you can convert the exported Json file on this page to generate your C# API client.
To ensure optimal conversion of your Postman collection, I recommend the following practices:
Save responses for all requests: This cannot be stressed enough. This allows Postman2CSharp to generate classes for your response json.
Put example json in request bodies that use it: As above, this allows Postman2CSharp to generate classes for your request json.
Use inherited authorization: This helps maintain consistency and will generate the best results.
Delete unused parameters: To ensure clean and optimized generated code, it is advisable to delete parameters that are not being used. Delete, not disable.
Use collection variables instead of other types of variables: Collection variables allow Postman2CSharp to do more code generation for you because their values are included in the exported json.
Before you head to the convert page and convert your collection, you should check out the Interactive Demo.
It will give you a feel for how Postman2CSharp works and apply changes to configurations in real time.There majority of configuration will be found on the Convert page. There are some additional configuration that you can configure on the Advanced Settings page; these configurations deal with how classes are generated from Json. For an explanation of configurations see ApiClient Configurations Explained.