|
| 1 | +# Databox - the C# library for the Static OpenAPI document of Push API resource |
| 2 | + |
| 3 | +Push API resources Open API documentation |
| 4 | + |
| 5 | +This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: |
| 6 | + |
| 7 | +- API version: 1.0 |
| 8 | +- SDK version: 0.0.2 |
| 9 | +- Generator version: 7.6.0 |
| 10 | +- Build package: org.openapitools.codegen.languages.CSharpClientCodegen |
| 11 | + |
| 12 | +<a id="frameworks-supported"></a> |
| 13 | +## Frameworks supported |
| 14 | + |
| 15 | +<a id="dependencies"></a> |
| 16 | +## Dependencies |
| 17 | + |
| 18 | +- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 13.0.2 or later |
| 19 | +- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 or later |
| 20 | +- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 5.0.0 or later |
| 21 | + |
| 22 | +The DLLs included in the package may not be the latest version. We recommend using [NuGet](https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages: |
| 23 | +``` |
| 24 | +Install-Package Newtonsoft.Json |
| 25 | +Install-Package JsonSubTypes |
| 26 | +Install-Package System.ComponentModel.Annotations |
| 27 | +``` |
| 28 | +<a id="installation"></a> |
| 29 | +## Installation |
| 30 | +Run the following command to generate the DLL |
| 31 | +- [Mac/Linux] `/bin/sh build.sh` |
| 32 | +- [Windows] `build.bat` |
| 33 | + |
| 34 | +Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces: |
| 35 | +```csharp |
| 36 | +using Databox.Api; |
| 37 | +using Databox.Client; |
| 38 | +using Databox.Model; |
| 39 | +``` |
| 40 | +<a id="packaging"></a> |
| 41 | +## Packaging |
| 42 | + |
| 43 | +A `.nuspec` is included with the project. You can follow the Nuget quickstart to [create](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#create-the-package) and [publish](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#publish-the-package) packages. |
| 44 | + |
| 45 | +This `.nuspec` uses placeholders from the `.csproj`, so build the `.csproj` directly: |
| 46 | + |
| 47 | +``` |
| 48 | +nuget pack -Build -OutputDirectory out Databox.csproj |
| 49 | +``` |
| 50 | + |
| 51 | +Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or [other host](https://docs.microsoft.com/en-us/nuget/hosting-packages/overview) and consume the new package via Nuget as usual. |
| 52 | + |
| 53 | +<a id="usage"></a> |
| 54 | +## Usage |
| 55 | + |
| 56 | +To use the API client with a HTTP proxy, setup a `System.Net.WebProxy` |
| 57 | +```csharp |
| 58 | +Configuration c = new Configuration(); |
| 59 | +System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/"); |
| 60 | +webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials; |
| 61 | +c.Proxy = webProxy; |
| 62 | +``` |
| 63 | + |
| 64 | +### Connections |
| 65 | +Each ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method. |
| 66 | + |
| 67 | +To better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see [here](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests#issues-with-the-original-httpclient-class-available-in-net) for details). To use your own HttpClient instance just pass it to the ApiClass constructor. |
| 68 | + |
| 69 | +```csharp |
| 70 | +HttpClientHandler yourHandler = new HttpClientHandler(); |
| 71 | +HttpClient yourHttpClient = new HttpClient(yourHandler); |
| 72 | +var api = new YourApiClass(yourHttpClient, yourHandler); |
| 73 | +``` |
| 74 | + |
| 75 | +If you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory. |
| 76 | + |
| 77 | +```csharp |
| 78 | +HttpClient yourHttpClient = new HttpClient(); |
| 79 | +var api = new YourApiClass(yourHttpClient); |
| 80 | +``` |
| 81 | +You'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available. |
| 82 | + |
| 83 | +Here an example of DI setup in a sample web project: |
| 84 | + |
| 85 | +```csharp |
| 86 | +services.AddHttpClient<YourApiClass>(httpClient => |
| 87 | + new PetApi(httpClient)); |
| 88 | +``` |
| 89 | + |
| 90 | + |
| 91 | +<a id="getting-started"></a> |
| 92 | +## Getting Started |
| 93 | + |
| 94 | +```csharp |
| 95 | +using System.Collections.Generic; |
| 96 | +using System.Diagnostics; |
| 97 | +using System.Net.Http; |
| 98 | +using Databox.Api; |
| 99 | +using Databox.Client; |
| 100 | +using Databox.Model; |
| 101 | + |
| 102 | +namespace Example |
| 103 | +{ |
| 104 | + public class Example |
| 105 | + { |
| 106 | + public static void Main() |
| 107 | + { |
| 108 | + |
| 109 | + Configuration config = new Configuration(); |
| 110 | + config.BasePath = "http://localhost:8080/q/openapi"; |
| 111 | + // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes |
| 112 | + HttpClient httpClient = new HttpClient(); |
| 113 | + HttpClientHandler httpClientHandler = new HttpClientHandler(); |
| 114 | + var apiInstance = new DefaultApi(httpClient, config, httpClientHandler); |
| 115 | + var payloadModel = new PayloadModel?(); // PayloadModel? | (optional) |
| 116 | +
|
| 117 | + try |
| 118 | + { |
| 119 | + apiInstance.RootPost(payloadModel); |
| 120 | + } |
| 121 | + catch (ApiException e) |
| 122 | + { |
| 123 | + Debug.Print("Exception when calling DefaultApi.RootPost: " + e.Message ); |
| 124 | + Debug.Print("Status Code: "+ e.ErrorCode); |
| 125 | + Debug.Print(e.StackTrace); |
| 126 | + } |
| 127 | + |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +<a id="documentation-for-api-endpoints"></a> |
| 134 | +## Documentation for API Endpoints |
| 135 | + |
| 136 | +All URIs are relative to *http://localhost:8080/q/openapi* |
| 137 | + |
| 138 | +Class | Method | HTTP request | Description |
| 139 | +------------ | ------------- | ------------- | ------------- |
| 140 | +*DefaultApi* | [**RootPost**](docs/DefaultApi.md#rootpost) | **POST** / | |
| 141 | + |
| 142 | + |
| 143 | +<a id="documentation-for-models"></a> |
| 144 | +## Documentation for Models |
| 145 | + |
| 146 | + - [Model.ApiResponse](docs/ApiResponse.md) |
| 147 | + - [Model.PayloadDataModel](docs/PayloadDataModel.md) |
| 148 | + - [Model.PayloadModel](docs/PayloadModel.md) |
| 149 | + |
| 150 | + |
| 151 | +<a id="documentation-for-authorization"></a> |
| 152 | +## Documentation for Authorization |
| 153 | + |
| 154 | + |
| 155 | +Authentication schemes defined for the API: |
| 156 | +<a id="basicAuth"></a> |
| 157 | +### basicAuth |
| 158 | + |
| 159 | +- **Type**: HTTP basic authentication |
| 160 | + |
0 commit comments