-
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathNonJsonApiController.cs
More file actions
64 lines (55 loc) · 1.82 KB
/
NonJsonApiController.cs
File metadata and controls
64 lines (55 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using JsonApiDotNetCoreExample.DocAnnotations;
using Microsoft.AspNetCore.Mvc;
namespace JsonApiDotNetCoreExample.Controllers;
[Route("[controller]")]
[Tags("nonJsonApi")]
public sealed class NonJsonApiController : ControllerBase
{
[HttpGet(Name = "welcomeGet")]
[HttpHead(Name = "welcomeHead")]
[EndpointDescription("Returns a single-element JSON array.")]
[ProducesResponseType<List<string>>(StatusCodes.Status200OK, "application/json")]
public IActionResult Get()
{
string[] result = ["Welcome!"];
return Ok(result);
}
[HttpPost]
[EndpointDescription("Returns a greeting text, based on your name.")]
[Consumes("application/json")]
[ProducesResponseType<string>(StatusCodes.Status200OK, "text/plain")]
[ProducesResponseType<string>(StatusCodes.Status400BadRequest, "text/plain")]
public async Task<IActionResult> PostAsync([FromBody] string? name)
{
await Task.Yield();
if (string.IsNullOrWhiteSpace(name))
{
return BadRequest("Please send your name.");
}
string result = $"Hello, {name}";
return Ok(result);
}
[HttpPut]
[EndpointDescription("Returns another greeting text.")]
[ProducesResponseType<string>(StatusCodes.Status200OK, "text/plain")]
[RequiresAdmin]
[ExpiresOn("2030-01-01")]
public IActionResult Put([FromQuery] string? name)
{
string result = $"Hi, {name}";
return Ok(result);
}
[HttpPatch]
[EndpointDescription("Wishes you a good day.")]
[ProducesResponseType<string>(StatusCodes.Status200OK, "text/plain")]
public IActionResult Patch([FromHeader] string? name)
{
string result = $"Good day, {name}";
return Ok(result);
}
[HttpDelete]
public IActionResult Delete()
{
return Ok("Bye.");
}
}