How to add more custom methods in HttpRequestMessageExtensions class

return Request.CreateResponse(HttpStatusCode.BadRequest, new mymethodresponse
                    ID= Idval,
                    Created= false

Here how to create more overloads for createresponse method

1 answer

  • answered 2022-05-05 10:30 Qing Guo

    Below is a work demo, you can refer to it.

    1.Create a HttpRequestMessageExtensions class

    public static class HttpRequestMessageExtensions
            public static HttpResponseMessage CreateResponse(this HttpRequestMessage request, HttpStatusCode statusCode, string TestParas)
                return new HttpResponseMessage
                    StatusCode = statusCode,
                    RequestMessage = request

    2.In controller like below

    public class OverloadController : Controller
            public HttpResponseMessage Call(HttpRequestMessage RequestMessage)
                return RequestMessage.CreateResponse();//do your staff...

    Result: enter image description here

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum