Interactive Demo


Try out all the different configurations Postman2CSharp has to offer with this interactive demo. See how configurations affected the generated ApiClient and Json classes. Changes are automatically saved on this page.


ApiClient Generation Configurations


For an in depth explanation on how these settings work, see ApiClient Configurations Explanation.


Important
SystemTextJson
Always

Multiple Response Handling
OneOf
ThrowException

Error Handling
None
LogException
Exception
Error

Function Configurations

Class Generation


Miscellaneous
PerAuthorityPerFolder

Generated Api Client


/// <summary>
/// This is the description of an example collection with 3 requests.
/// </summary>
public class ExampleApiClient : IExampleApiClient
{
    private readonly HttpClient _httpClient;
    private readonly string _baseUrl = "someurl.com";
    private readonly string _version = "v1";
    private readonly string _apiKey;
    public ExampleApiClient(HttpClient httpClient, IConfiguration config)
    {
        _httpClient = httpClient;
        _httpClient.BaseAddress = new Uri($"https://{_baseUrl}/api/{_version}/users/");

        _apiKey = config["Path:ToApiKey"];
        _httpClient.DefaultRequestHeaders.Add($"api_key", _apiKey);
    }

    /// <summary>
    /// Use this endpoint to search for users when you don't have an id.
    /// </summary>
    public Task<SearchUsersResponse> SearchUsers(SearchUsersParameters queryParameters)
    {
        var parametersDict = queryParameters.ToDictionary();
        var queryString = QueryHelpers.AddQueryString($"", parametersDict);
        return _httpClient.GetFromJsonAsync<SearchUsersResponse>(queryString);
    }

    /// <summary>
    /// Use this endpoint to get a user when you have an id
    /// </summary>
    /// <param name="id">
    /// The id of the user
    /// </param>
    public Task<Users> GetUserById(string id)
    {
        return _httpClient.GetFromJsonAsync<Users>($"{id}");
    }

    /// <summary>
    /// Use this endpoint to get additional details associated with a user that aren't included in other endpoints
    /// </summary>
    /// <param name="id">
    /// The id of the user
    /// </param>
    public async Task<Stream> GetUserDetails(string id)
    {
        var headers = new Dictionary<string, string>()
        {
            { $"hggg", $"" }
        };

        var response = await _httpClient.GetAsync($"{id}/details", headers);
        return await response.Content.ReadAsStreamAsync();
    }
}


Json Used


{
	"info": {
		"_postman_id": "f567abd6-4da7-44cc-b2d8-d5e36e4649c8",
		"name": "Example",
		"description": "This is the description of an example collection with 3 requests.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "24405183"
	},
	"item": [
		{
			"name": "SearchUsers",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "https://{{base_url}}/api/{{version}}/users?email=&firstName=",
					"protocol": "https",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"api",
						"{{version}}",
						"users"
					],
					"query": [
						{
							"key": "email",
							"value": "",
							"description": "The email of the user"
						},
						{
							"key": "firstName",
							"value": "",
							"description": "The first name of the user"
						},
						{
							"key": "lastName",
							"value": "",
							"description": "The last name of the user",
							"disabled": true
						}
					]
				},
				"description": "Use this endpoint to search for users when you don't have an id."
			},
			"response": [
				{
					"name": "200",
					"originalRequest": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "https://{{base_url}}/api/{{version}}/users/:id",
							"protocol": "https",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"{{version}}",
								"users",
								":id"
							],
							"variable": [
								{
									"key": "id",
									"value": null
								}
							]
						}
					},
					"status": "OK",
					"code": 200,
					"_postman_previewlanguage": "json",
					"header": [
						{
							"key": "Content-Type",
							"value": "application/json",
							"name": "Content-Type",
							"description": "",
							"type": "text"
						}
					],
					"cookie": [],
					"body": "{\n    \"total\": 3,\n    \"users\": [\n        {\n            \"firstName\": \"test\",\n            \"lastName\": \"test\",\n            \"email\": \"test@gmail\"\n        },\n        {\n            \"firstName\": \"test\",\n            \"lastName\": \"test\",\n            \"email\": \"test@gmail\"\n        },  \n        {\n            \"firstName\": \"test\",\n            \"lastName\": \"test\",\n            \"email\": \"test@gmail\",\n            \"isPaidUser\" : true\n        }\n    ]\n}"
				},
				{
					"name": "401",
					"originalRequest": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "https://{{base_url}}/api/{{version}}/users/:id",
							"protocol": "https",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"{{version}}",
								"users",
								":id"
							],
							"variable": [
								{
									"key": "id",
									"value": null
								}
							]
						}
					},
					"status": "Unauthorized",
					"code": 401,
					"_postman_previewlanguage": "json",
					"header": [
						{
							"key": "Content-Type",
							"value": "application/json",
							"name": "Content-Type",
							"description": "",
							"type": "text"
						}
					],
					"cookie": [],
					"body": "{\n  \"code\": 401,\n  \"status\": \"error\",\n  \"reason\": \"Unauthorized\",\n  \"details\": \"Invalid credentials provided\"\n}"
				},
				{
					"name": "403",
					"originalRequest": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "https://{{base_url}}/api/{{version}}/users/:id",
							"protocol": "https",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"{{version}}",
								"users",
								":id"
							],
							"variable": [
								{
									"key": "id",
									"value": null
								}
							]
						}
					},
					"status": "Forbidden",
					"code": 403,
					"_postman_previewlanguage": "json",
					"header": [
						{
							"key": "Content-Type",
							"value": "application/json",
							"name": "Content-Type",
							"description": "",
							"type": "text"
						}
					],
					"cookie": [],
					"body": "{\r\n  \"errorCode\": 403,\r\n  \"errorType\": \"Forbidden\",\r\n  \"message\": \"Access denied\",\r\n  \"userMessage\": \"You do not have the necessary permissions to perform this action\"\r\n}"
				},
				{
					"name": "500",
					"originalRequest": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "https://{{base_url}}/api/{{version}}/users/:id",
							"protocol": "https",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"{{version}}",
								"users",
								":id"
							],
							"variable": [
								{
									"key": "id",
									"value": null
								}
							]
						}
					},
					"status": "Internal Server Error",
					"code": 500,
					"_postman_previewlanguage": "json",
					"header": [
						{
							"key": "Content-Type",
							"value": "application/json",
							"name": "Content-Type",
							"description": "",
							"type": "text"
						}
					],
					"cookie": [],
					"body": "{\r\n  \"httpStatus\": 500,\r\n  \"errorDescription\": \"Internal Server Error\",\r\n  \"exceptionDetails\": {\r\n    \"cause\": \"NullPointerException\",\r\n    \"message\": \"Unexpected error occurred\"\r\n  }\r\n}"
				}
			]
		},
		{
			"name": "GetUserById",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "https://{{base_url}}/api/{{version}}/users/:id",
					"protocol": "https",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"api",
						"{{version}}",
						"users",
						":id"
					],
					"variable": [
						{
							"key": "id",
							"value": "",
							"description": "The id of the user"
						}
					]
				},
				"description": "Use this endpoint to get a user when you have an id"
			},
			"response": [
				{
					"name": "200",
					"originalRequest": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "https://{{base_url}}/api/{{version}}/users/:id",
							"protocol": "https",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"{{version}}",
								"users",
								":id"
							],
							"variable": [
								{
									"key": "id",
									"value": null
								}
							]
						}
					},
					"status": "OK",
					"code": 200,
					"_postman_previewlanguage": "json",
					"header": [
						{
							"key": "Content-Type",
							"value": "application/json",
							"name": "Content-Type",
							"description": "",
							"type": "text"
						}
					],
					"cookie": [],
					"body": "{\r\n    \"firstName\" : \"test\",\r\n    \"lastName\" : \"test\",\r\n    \"email\" : \"test@gmail\"\r\n}"
				},
				{
					"name": "401",
					"originalRequest": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "https://{{base_url}}/api/{{version}}/users/:id",
							"protocol": "https",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"{{version}}",
								"users",
								":id"
							],
							"variable": [
								{
									"key": "id",
									"value": null
								}
							]
						}
					},
					"status": "Unauthorized",
					"code": 401,
					"_postman_previewlanguage": "json",
					"header": [
						{
							"key": "Content-Type",
							"value": "application/json",
							"name": "Content-Type",
							"description": "",
							"type": "text"
						}
					],
					"cookie": [],
					"body": "{\r\n  \"code\": 401,\r\n  \"status\": \"error\",\r\n  \"reason\": \"Unauthorized\",\r\n  \"details\": \"Invalid credentials provided\"\r\n}"
				},
				{
					"name": "403",
					"originalRequest": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "https://{{base_url}}/api/{{version}}/users/:id",
							"protocol": "https",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"{{version}}",
								"users",
								":id"
							],
							"variable": [
								{
									"key": "id",
									"value": null
								}
							]
						}
					},
					"status": "Forbidden",
					"code": 403,
					"_postman_previewlanguage": "json",
					"header": [
						{
							"key": "Content-Type",
							"value": "application/json",
							"name": "Content-Type",
							"description": "",
							"type": "text"
						}
					],
					"cookie": [],
					"body": "{\n    \"errorCode\": 403,\n    \"errorType\": \"Forbidden\",\n    \"message\": \"Access denied\",\n    \"userMessage\": \"You do not have the necessary permissions to perform this action\"\n}"
				},
				{
					"name": "500",
					"originalRequest": {
						"method": "GET",
						"header": [],
						"url": {
							"raw": "https://{{base_url}}/api/{{version}}/users/:id",
							"protocol": "https",
							"host": [
								"{{base_url}}"
							],
							"path": [
								"api",
								"{{version}}",
								"users",
								":id"
							],
							"variable": [
								{
									"key": "id",
									"value": null
								}
							]
						}
					},
					"status": "Internal Server Error",
					"code": 500,
					"_postman_previewlanguage": "json",
					"header": [
						{
							"key": "Content-Type",
							"value": "application/json",
							"name": "Content-Type",
							"description": "",
							"type": "text"
						}
					],
					"cookie": [],
					"body": "{\n    \"httpStatus\": 500,\n    \"errorDescription\": \"Internal Server Error\",\n    \"exceptionDetails\": {\n        \"cause\": \"NullPointerException\",\n        \"message\": \"Unexpected error occurred\"\n    }\n}"
				}
			]
		},
		{
			"name": "GetUserDetails",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "hggg",
						"value": "",
						"description": "accidental keyboard mash",
						"type": "text",
						"disabled": true
					}
				],
				"url": {
					"raw": "https://{{base_url}}/api/{{version}}/users/:id/details",
					"protocol": "https",
					"host": [
						"{{base_url}}"
					],
					"path": [
						"api",
						"{{version}}",
						"users",
						":id",
						"details"
					],
					"variable": [
						{
							"key": "id",
							"value": "",
							"description": "The id of the user"
						}
					]
				},
				"description": "Use this endpoint to get additional details associated with a user that aren't included in other endpoints"
			},
			"response": []
		}
	],
	"auth": {
		"type": "apikey",
		"apikey": [
			{
				"key": "value",
				"value": "{{api_key}}",
				"type": "string"
			},
			{
				"key": "key",
				"value": "api_key",
				"type": "string"
			}
		]
	},
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "base_url",
			"value": "someurl.com",
			"type": "string"
		},
		{
			"key": "api_key",
			"value": "some value",
			"type": "string"
		},
		{
			"key": "version",
			"value": "v1",
			"type": "string"
		}
	]
}



Copyright © 2024 - Postman2CSharp All Rights Reserved
GitHub Repo Support me and the project