Pilz.Net aktualisieren
27
Pilz.Net.md
27
Pilz.Net.md
@@ -25,10 +25,10 @@ Creating a request can be done with the asyncron `IApiClient.MakeRequest()` and
|
|||||||
|
|
||||||
```cs
|
```cs
|
||||||
// Run asyncron
|
// Run asyncron
|
||||||
var result = await client.SendRequest<SDxResponse>("/sdx/get");
|
var result = await client.SendRequest<SDxGetResponse>("/sdx/get");
|
||||||
|
|
||||||
// Run syncron
|
// Run syncron
|
||||||
var result = client.SendRequest<SDxResponse>("/sdx/get").Result;
|
var result = client.SendRequest<SDxGetResponse>("/sdx/get").Result;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Check result
|
### Check result
|
||||||
@@ -61,6 +61,23 @@ result.EnsureOk();
|
|||||||
|
|
||||||
If the status code is fine and the message is not null, you can use it. It's typed as `T` while `T` is an type that inherits from `ApiMessage` which you can define at `SendRequest<T>()` method.
|
If the status code is fine and the message is not null, you can use it. It's typed as `T` while `T` is an type that inherits from `ApiMessage` which you can define at `SendRequest<T>()` method.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Example messages</summay>
|
||||||
|
|
||||||
|
```cs
|
||||||
|
public class SDxGetRequest(int id)
|
||||||
|
{
|
||||||
|
public int Id { get; } = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SDxGetResponse(List<SDx> sdx)
|
||||||
|
{
|
||||||
|
public List<SDx> SDx { get; } = sdx;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## Server
|
## Server
|
||||||
|
|
||||||
### Create new ApiServer
|
### Create new ApiServer
|
||||||
@@ -93,7 +110,7 @@ When a request reaches the server then the server checks each registered handler
|
|||||||
[ApiMessageHandler("/sdx/get")]
|
[ApiMessageHandler("/sdx/get")]
|
||||||
private ApiResult GetSDx()
|
private ApiResult GetSDx()
|
||||||
{
|
{
|
||||||
return ApiResult.Ok(new SDxResponse(Database.SDxList.Select(s => s.ToClient())));
|
return ApiResult.Ok(new SDxResponse([.. Database.SDxList.Select(s => s.ToClient())]));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -107,9 +124,9 @@ private ApiResult GetSDx(SDxGetRequest message)
|
|||||||
{
|
{
|
||||||
if (Database.SDxList.FirstOrDefault(s => s.Id == message.Id) is not SDx sdx)
|
if (Database.SDxList.FirstOrDefault(s => s.Id == message.Id) is not SDx sdx)
|
||||||
return ApiResult.NotFound();
|
return ApiResult.NotFound();
|
||||||
return ApiResult.Ok(new SDxGetResponse(sdx);
|
return ApiResult.Ok(new SDxGetResponse([.. sdx]);
|
||||||
}
|
}
|
||||||
return ApiResult.Ok(new SDxGetResponse(Database.SDxList.Select(s => s.ToClient())));
|
return ApiResult.Ok(new SDxGetResponse([.. Database.SDxList.Select(s => s.ToClient())]));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user