working on various components of the documentation

This commit is contained in:
Leon Hoppe
2024-11-22 11:42:21 +01:00
parent a531cd7a47
commit 2bc8a5d70b
9 changed files with 138 additions and 5 deletions

0
docs/api/endpoints.md Normal file
View File

View File

@@ -1,5 +1,5 @@
# Ho to use the Web API version
This Installation adds all HopFrame [endpoints](./endpoints.md) and [services](./services.md) to the application.
This Installation adds all HopFrame [endpoints](./endpoints.md) and [repositories](../repositories.md) to the application.
1. Add the HopFrame.Api library to your project:

33
docs/api/logicresults.md Normal file
View File

@@ -0,0 +1,33 @@
# LogicResults
LogicResults provide another layer of abstraction above the ActionResults.
They help you sending the right `HttpStatusCode` with the right data.
## Usage
1. Create an endpoint that returns an `ActionResult`:
```csharp
[HttpGet("hello")]
public ActionResult<string> Hello() {
return new ActionResult<string>("Hello, World!");
}
```
2. Now instead of directly returning the `ActionResult`, return a `LogicResult`
```csharp
[HttpGet("hello")]
public ActionResult<string> Hello() {
return LogicResult<string>.Ok("Hello, World!");
}
```
3. This allows you to very easily change the return type by simply calling the right function
```csharp
[HttpGet("hello")]
public ActionResult<string> Hello() {
if (!Auth.IsLoggedIn)
return LogicResult<string>.Forbidden();
return LogicResult<string>.Ok("Hello, World!");
}
```
**Hint:** You can also provide an error message for status codes that are not in the 200 range.