File tree Expand file tree Collapse file tree
Commands.Http/Commands.Http/Results
Commands.Samples/Commands.Samples.Http Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,13 +63,33 @@ public class HttpResult : IHttpResult
6363 /// <inheritdoc />
6464 public IDictionary < string , string > Headers { get ; } = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
6565
66+ /// <summary>
67+ /// Initializes a new instance of the <see cref="HttpResult"/> class with the specified status code.
68+ /// </summary>
69+ /// <param name="code">The numeric status code of this result. Converted to a value of <see cref="HttpStatusCode"/> on initialization.</param>
70+ public HttpResult ( int code )
71+ : this ( ( HttpStatusCode ) code )
72+ {
73+ }
74+
6675 /// <summary>
6776 /// Initializes a new instance of the <see cref="HttpResult"/> class with the specified status code.
6877 /// </summary>
6978 /// <param name="code">The status code of this result.</param>
7079 public HttpResult ( HttpStatusCode code )
7180 => StatusCode = code ;
7281
82+ /// <summary>
83+ /// Initializes a new instance of the <see cref="HttpResult"/> class with the specified status code, content, and content type.
84+ /// </summary>
85+ /// <param name="code">The status code of this result. Converted to a value of <see cref="HttpStatusCode"/> on initialization.</param>
86+ /// <param name="content">The content of this result.</param>
87+ /// <param name="contentType">The content type of this result.</param>
88+ public HttpResult ( int code , [ DisallowNull ] object content , string ? contentType = null )
89+ : this ( ( HttpStatusCode ) code , content , contentType )
90+ {
91+ }
92+
7393 /// <summary>
7494 /// Initializes a new instance of the <see cref="HttpResult"/> class with the specified status code, content, and content type.
7595 /// </summary>
Original file line number Diff line number Diff line change 6262
6363 // This adds a command that can be invoked via HTTP GET requests under the following url: http://localhost:5000/ping.
6464 // The command responds with a simple "OK!" message.
65- components . Add ( new Command ( [ HttpGet ] ( ) => new HttpResult ( HttpStatusCode . OK ) , "ping" ) ) ;
65+ components . Add ( new Command ( [ HttpGet ] ( ) => new HttpResult ( 200 ) , "ping" ) ) ;
6666
6767 // This adds a command that can be invoked via HTTP GET requests under the following url: http://localhost:5000/help.
6868 // The command lists all available commands in the component tree, providing a simple way to discover what commands are available.
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ host.UseComponents(components =>
5656{
5757 components .Add (new Command ([HttpGet ] () =>
5858 {
59- return HttpResult . Ok ( " OK! " );
59+ return new HttpResult ( 200 );
6060 }, " ping" ));
6161});
6262
@@ -87,7 +87,7 @@ public sealed class HttpModule : HttpCommandModule<HttpCommandContext>
8787{
8888 [HttpGet (" get" )]
8989 public IHttpResult Get (int initialValue , Guid anotherValue )
90- => HttpResult . Ok ($" Hello World; {initialValue }, {anotherValue }" );
90+ => Ok ($" Hello World; {initialValue }, {anotherValue }" );
9191}
9292```
9393
@@ -104,7 +104,7 @@ public sealed class HttpModule : HttpCommandModule<HttpCommandContext>
104104{
105105 [HttpPost (" post" )]
106106 public IHttpResult Post ([JsonBody ] string content )
107- => HttpResult . Ok ($" Received: {content }" );
107+ => Ok ($" Received: {content }" );
108108}
109109```
110110
@@ -128,7 +128,7 @@ public sealed class HttpModule : HttpCommandModule<HttpCommandContext>
128128{
129129 [HttpMethod (" CUSTOM" , " custom" )]
130130 public IHttpResult CustomMethod ()
131- => HttpResult . Ok (" This is a custom HTTP method response." );
131+ => Ok (" This is a custom HTTP method response." );
132132}
133133```
134134
You can’t perform that action at this time.
0 commit comments