33namespace JsonApiDotNetCoreExample . Controllers ;
44
55[ Route ( "[controller]" ) ]
6+ [ Tags ( "nonJsonApi" ) ]
67public sealed class NonJsonApiController : ControllerBase
78{
8- [ HttpGet ]
9+ [ HttpGet ( Name = "welcomeGet" ) ]
10+ [ HttpHead ( Name = "welcomeHead" ) ]
11+ [ EndpointDescription ( "Returns a single-element JSON array." ) ]
12+ [ ProducesResponseType < List < string > > ( StatusCodes . Status200OK , "application/json" ) ]
913 public IActionResult Get ( )
1014 {
1115 string [ ] result = [ "Welcome!" ] ;
@@ -14,12 +18,15 @@ public IActionResult Get()
1418 }
1519
1620 [ HttpPost ]
17- public async Task < IActionResult > PostAsync ( )
21+ [ EndpointDescription ( "Returns a greeting text, based on your name." ) ]
22+ [ Consumes ( "application/json" ) ]
23+ [ ProducesResponseType < string > ( StatusCodes . Status200OK , "text/plain" ) ]
24+ [ ProducesResponseType < string > ( StatusCodes . Status400BadRequest , "text/plain" ) ]
25+ public async Task < IActionResult > PostAsync ( [ FromBody ] string ? name )
1826 {
19- using var reader = new StreamReader ( Request . Body , leaveOpen : true ) ;
20- string name = await reader . ReadToEndAsync ( ) ;
27+ await Task . Yield ( ) ;
2128
22- if ( string . IsNullOrEmpty ( name ) )
29+ if ( string . IsNullOrWhiteSpace ( name ) )
2330 {
2431 return BadRequest ( "Please send your name." ) ;
2532 }
@@ -29,14 +36,18 @@ public async Task<IActionResult> PostAsync()
2936 }
3037
3138 [ HttpPut ]
32- public IActionResult Put ( [ FromBody ] string name )
39+ [ EndpointDescription ( "Returns another greeting text." ) ]
40+ [ ProducesResponseType < string > ( StatusCodes . Status200OK , "text/plain" ) ]
41+ public IActionResult Put ( [ FromQuery ] string ? name )
3342 {
3443 string result = $ "Hi, { name } ";
3544 return Ok ( result ) ;
3645 }
3746
3847 [ HttpPatch ]
39- public IActionResult Patch ( string name )
48+ [ EndpointDescription ( "Wishes you a good day." ) ]
49+ [ ProducesResponseType < string > ( StatusCodes . Status200OK , "text/plain" ) ]
50+ public IActionResult Patch ( [ FromHeader ] string ? name )
4051 {
4152 string result = $ "Good day, { name } ";
4253 return Ok ( result ) ;
0 commit comments