Skip to content

Commit 6bdbcd5

Browse files
committed
API controllers examples added
1 parent 2841590 commit 6bdbcd5

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ Then just run project via F5 (it will download all required nuget and npm packag
7575

7676
## [Detailed documentation](https://github.com/i4004/Simplify.Web/wiki)
7777

78-
### API controller example
78+
### API outgoing JSON controller example
7979

8080
```csharp
81-
[Get("api/weatherTypes")]
81+
[Get("api/v1/weatherTypes")]
8282
public class SampleDataController : Controller
8383
{
8484
private static readonly string[] Summaries =
@@ -102,6 +102,40 @@ public class SampleDataController : Controller
102102
}
103103
```
104104

105+
### API ingoing JSON controller example
106+
107+
```csharp
108+
[Post("api/v1/sendMessage")]
109+
public class SampleDataController : Controller<SampleModel>
110+
{
111+
public override ControllerResponse Invoke()
112+
{
113+
try
114+
{
115+
Trace.WriteLine($"Object with message received: {Model.Message}");
116+
117+
return NoContent();
118+
}
119+
catch (Exception e) when (e is ModelValidationException || e is Newtonsoft.Json.JsonException)
120+
{
121+
return StatusCode(400, e.Message);
122+
}
123+
catch (Exception e)
124+
{
125+
Console.WriteLine(e);
126+
127+
return StatusCode(500, "Site error!");
128+
}
129+
}
130+
}
131+
132+
public class SampleModel
133+
{
134+
[Required]
135+
public string Message { get; set; }
136+
}
137+
```
138+
105139
### Some simple HTML generation controllers example
106140

107141
#### Static page controller

0 commit comments

Comments
 (0)