Meitner 0.4.3
dotnet add package Meitner --version 0.4.3
NuGet\Install-Package Meitner -Version 0.4.3
<PackageReference Include="Meitner" Version="0.4.3" />
<PackageVersion Include="Meitner" Version="0.4.3" />
<PackageReference Include="Meitner" />
paket add Meitner --version 0.4.3
#r "nuget: Meitner, 0.4.3"
#:package Meitner@0.4.3
#addin nuget:?package=Meitner&version=0.4.3
#tool nuget:?package=Meitner&version=0.4.3
Meitner
SDK Example Usage
Example
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(security: new Security() {
Option1 = new SecurityOption1() {
ClientCredentials = "<YOUR_API_KEY_HERE>",
ClientSecret = "<YOUR_API_KEY_HERE>",
},
});
SchoolListResponse? res = await sdk.Schools.ListAsync(
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
Authentication
Per-Client Security Schemes
This SDK supports multiple security scheme combinations globally. You can choose from one of the alternatives through the security optional parameter when initializing the SDK client instance. The selected option will be used by default to authenticate with the API for all operations that support it.
Option1
All of the following schemes must be satisfied to use the Option1 alternative:
| Name | Type | Scheme |
|---|---|---|
ClientCredentials |
apiKey | API key |
ClientSecret |
apiKey | API key |
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(security: new Security() {
Option1 = new SecurityOption1() {
ClientCredentials = "<YOUR_API_KEY_HERE>",
ClientSecret = "<YOUR_API_KEY_HERE>",
},
});
SchoolListResponse? res = await sdk.Schools.ListAsync(
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
Option2
The Option2 alternative relies on the following scheme:
| Name | Type | Scheme |
|---|---|---|
ClientID<br/>ClientSecret<br/>TokenURL |
oauth2 | OAuth2 Client Credentials Flow |
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(security: new Security() {
Option2 = new SecurityOption2() {
ClientID = "<YOUR_CLIENT_ID_HERE>",
ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
TokenURL = "/oauth/token",
},
});
SchoolListResponse? res = await sdk.Schools.ListAsync(
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned response object will have a Next method that can be called to pull down the next group of results. If the
return value of Next is null, then there are no more pages to be fetched.
Here's an example of one such pagination call:
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(security: new Security() {
Option1 = new SecurityOption1() {
ClientCredentials = "<YOUR_API_KEY_HERE>",
ClientSecret = "<YOUR_API_KEY_HERE>",
},
});
SchoolListResponse? res = await sdk.Schools.ListAsync(
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply pass a RetryConfig to the call:
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(security: new Security() {
Option1 = new SecurityOption1() {
ClientCredentials = "<YOUR_API_KEY_HERE>",
ClientSecret = "<YOUR_API_KEY_HERE>",
},
});
SchoolListResponse? res = await sdk.Schools.ListAsync(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
If you'd like to override the default retry strategy for all operations that support retries, you can use the RetryConfig optional parameter when intitializing the SDK:
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
security: new Security() {
Option1 = new SecurityOption1() {
ClientCredentials = "<YOUR_API_KEY_HERE>",
ClientSecret = "<YOUR_API_KEY_HERE>",
},
}
);
SchoolListResponse? res = await sdk.Schools.ListAsync(
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
Error Handling
MeitnerException is the base exception class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
|---|---|---|
Message |
string | Error message |
Request |
HttpRequestMessage | HTTP request object |
Response |
HttpResponseMessage | HTTP response object |
Some exceptions in this SDK include an additional Payload field, which will contain deserialized custom error data when present. Possible exceptions are listed in the Error Classes section.
Example
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Errors;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(security: new Security() {
Option1 = new SecurityOption1() {
ClientCredentials = "<YOUR_API_KEY_HERE>",
ClientSecret = "<YOUR_API_KEY_HERE>",
},
});
try
{
SchoolListResponse? res = await sdk.Schools.ListAsync(
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
}
catch (MeitnerException ex) // all SDK exceptions inherit from MeitnerException
{
// ex.ToString() provides a detailed error message
System.Console.WriteLine(ex);
// Base exception fields
HttpRequestMessage request = ex.Request;
HttpResponseMessage response = ex.Response;
var statusCode = (int)response.StatusCode;
var responseBody = ex.Body;
if (ex is Error400ResponseBody) // different exceptions may be thrown depending on the method
{
// Check error data fields
Error400ResponseBodyPayload payload = ex.Payload;
Error400ResponseBodyError Error = payload.Error;
HTTPMetadata HttpMeta = payload.HttpMeta;
}
// An underlying cause may be provided
if (ex.InnerException != null)
{
Exception cause = ex.InnerException;
}
}
catch (OperationCanceledException ex)
{
// CancellationToken was cancelled
}
catch (System.Net.Http.HttpRequestException ex)
{
// Check ex.InnerException for Network connectivity errors
}
Error Classes
Primary exceptions:
MeitnerException: The base class for HTTP error responses.Error400ResponseBody: Bad Request - The request was malformed or contained invalid parameters. Status code400.Error401ResponseBody: Unauthorized - The request is missing valid authentication credentials. Status code401.Error403ResponseBody: Forbidden - Request is authenticated, but the user is not allowed to perform the operation. Status code403.Error404ResponseBody: Not Found - The requested resource does not exist. Status code404.Error409ResponseBody: Conflict - The request could not be completed due to a conflict. Status code409.Error429ResponseBody: Too Many Requests - When the rate limit has been exceeded. Status code429.Error500ResponseBody: Internal Server Error - An unexpected server error occurred. Status code500.
Less common exceptions (31)
System.Net.Http.HttpRequestException: Network connectivity error. For more details about the underlying cause, inspect theex.InnerException.Inheriting from
MeitnerException:SchoolCreate422ResponseBodyException: Validation error for School Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*SchoolSearch422ResponseBodyException: Validation error for School Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*SchoolUpdate422ResponseBodyException: Validation error for School Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GroupCreate422ResponseBodyException: Validation error for Group Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GroupSearch422ResponseBodyException: Validation error for Group Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GroupUpdate422ResponseBodyException: Validation error for Group Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*EmployeeCreate422ResponseBodyException: Validation error for Employee Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*EmployeeSearch422ResponseBodyException: Validation error for Employee Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*EmployeeUpdate422ResponseBodyException: Validation error for Employee Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*EmployeePlacementCreate422ResponseBodyException: Validation error for EmployeePlacement Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*EmployeePlacementSearch422ResponseBodyException: Validation error for EmployeePlacement Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*EmployeePlacementUpdate422ResponseBodyException: Validation error for EmployeePlacement Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GuardianCreate422ResponseBodyException: Validation error for Guardian Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GuardianSearch422ResponseBodyException: Validation error for Guardian Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GuardianUpdate422ResponseBodyException: Validation error for Guardian Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*StudentCreate422ResponseBodyException: Validation error for Student Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*StudentSearch422ResponseBodyException: Validation error for Student Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*StudentUpdate422ResponseBodyException: Validation error for Student Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*StudentPlacementCreate422ResponseBodyException: Validation error for StudentPlacement Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*StudentPlacementSearch422ResponseBodyException: Validation error for StudentPlacement Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*StudentPlacementUpdate422ResponseBodyException: Validation error for StudentPlacement Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*AuditEventSearch422ResponseBodyException: Validation error for AuditEvent Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GradeElementaryCreate422ResponseBodyException: Validation error for GradeElementary Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GradeElementaryUpdate422ResponseBodyException: Validation error for GradeElementary Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GradeUpperSecondaryCreate422ResponseBodyException: Validation error for GradeUpperSecondary Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*GradeUpperSecondaryUpdate422ResponseBodyException: Validation error for GradeUpperSecondary Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*UnitCreate422ResponseBodyException: Validation error for Unit Create operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*UnitSearch422ResponseBodyException: Validation error for Unit Search operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*UnitUpdate422ResponseBodyException: Validation error for Unit Update operation - request data failed validation. Status code422. Applicable to 1 of 61 methods.*ResponseValidationError: Thrown when the response data could not be deserialized into the expected type.
* Refer to the relevant documentation to determine whether an exception applies to a specific operation.
Server Selection
Select Server by Name
You can override the default server globally by passing a server name to the server: string optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
| Name | Server | Description |
|---|---|---|
production |
https://api.meitner.se/directory/v1 |
Server to use in production |
staging |
https://api.staging.meitner.se/directory/v1 |
Server to use when building and testing the API |
Example
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(
server: SDKConfig.Server.Production,
security: new Security() {
Option1 = new SecurityOption1() {
ClientCredentials = "<YOUR_API_KEY_HERE>",
ClientSecret = "<YOUR_API_KEY_HERE>",
},
}
);
SchoolListResponse? res = await sdk.Schools.ListAsync(
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the serverUrl: string optional parameter when initializing the SDK client instance. For example:
using Meitner;
using Meitner.Models.Components;
using Meitner.Models.Requests;
var sdk = new MeitnerSDK(
serverUrl: "https://api.meitner.se/directory/v1",
security: new Security() {
Option1 = new SecurityOption1() {
ClientCredentials = "<YOUR_API_KEY_HERE>",
ClientSecret = "<YOUR_API_KEY_HERE>",
},
}
);
SchoolListResponse? res = await sdk.Schools.ListAsync(
limit: 1,
offset: 0
);
while(res != null)
{
// handle items
res = await res.Next!();
}
Custom HTTP Client
The C# SDK makes API calls using an ISpeakeasyHttpClient that wraps the native
HttpClient. This
client provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle
errors and response.
The ISpeakeasyHttpClient interface allows you to either use the default SpeakeasyHttpClient that comes with the SDK,
or provide your own custom implementation with customized configuration such as custom message handlers, timeouts,
connection pooling, and other HTTP client settings.
The following example shows how to create a custom HTTP client with request modification and error handling:
using Meitner;
using Meitner.Utils;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
// Create a custom HTTP client
public class CustomHttpClient : ISpeakeasyHttpClient
{
private readonly ISpeakeasyHttpClient _defaultClient;
public CustomHttpClient()
{
_defaultClient = new SpeakeasyHttpClient();
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
// Add custom header and timeout
request.Headers.Add("x-custom-header", "custom value");
request.Headers.Add("x-request-timeout", "30");
try
{
var response = await _defaultClient.SendAsync(request, cancellationToken);
// Log successful response
Console.WriteLine($"Request successful: {response.StatusCode}");
return response;
}
catch (Exception error)
{
// Log error
Console.WriteLine($"Request failed: {error.Message}");
throw;
}
}
public void Dispose()
{
_httpClient?.Dispose();
_defaultClient?.Dispose();
}
}
// Use the custom HTTP client with the SDK
var customHttpClient = new CustomHttpClient();
var sdk = new Meitner(client: customHttpClient);
You can also provide a completely custom HTTP client with your own configuration:
using Meitner.Utils;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
// Custom HTTP client with custom configuration
public class AdvancedHttpClient : ISpeakeasyHttpClient
{
private readonly HttpClient _httpClient;
public AdvancedHttpClient()
{
var handler = new HttpClientHandler()
{
MaxConnectionsPerServer = 10,
// ServerCertificateCustomValidationCallback = customCertValidation, // Custom SSL validation if needed
};
_httpClient = new HttpClient(handler)
{
Timeout = TimeSpan.FromSeconds(30)
};
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
return await _httpClient.SendAsync(request, cancellationToken ?? CancellationToken.None);
}
public void Dispose()
{
_httpClient?.Dispose();
}
}
var sdk = Meitner.Builder()
.WithClient(new AdvancedHttpClient())
.Build();
For simple debugging, you can enable request/response logging by implementing a custom client:
public class LoggingHttpClient : ISpeakeasyHttpClient
{
private readonly ISpeakeasyHttpClient _innerClient;
public LoggingHttpClient(ISpeakeasyHttpClient innerClient = null)
{
_innerClient = innerClient ?? new SpeakeasyHttpClient();
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
// Log request
Console.WriteLine($"Sending {request.Method} request to {request.RequestUri}");
var response = await _innerClient.SendAsync(request, cancellationToken);
// Log response
Console.WriteLine($"Received {response.StatusCode} response");
return response;
}
public void Dispose() => _innerClient?.Dispose();
}
var sdk = new Meitner(client: new LoggingHttpClient());
The SDK also provides built-in hook support through the SDKConfiguration.Hooks system, which automatically handles
BeforeRequestAsync, AfterSuccessAsync, and AfterErrorAsync hooks for advanced request lifecycle management.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- newtonsoft.json (>= 13.0.3)
- nodatime (>= 3.1.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.