HttpRequestMessage: Add ctor with string HttpMethod

Topics: Web Api
Aug 25, 2011 at 12:29 PM

Currently the ctors of HttpRequestMessage does only accept the common fixed set of HTTP methods (ENUM HttpMethod)

But what if i want to use the WEBDAV methods? Or what if i want to use the PATCH method (proposed standard [1]).

My proposal is to add another ctor, where i can pass a custom HTTP method.

 

[1] http://tools.ietf.org/html/rfc5789

Aug 25, 2011 at 3:49 PM
Edited Aug 25, 2011 at 3:52 PM

HttpMethod isn't an enum.  You can extend it's functionality to support WebDAV.  Here's an example class:

/// <summary>
/// Defines additional <see cref="HttpMethod"/>s for RESTful service consumption.
/// </summary>
public class HttpVerb : HttpMethod
{
    #region Fields

    private static readonly HttpVerb _PropFind = new HttpVerb("PROPFIND");

    #endregion

    #region Constructors

    /// <summary>
    /// Initializes a new instance of the <see cref="HttpVerb"/> class.
    /// </summary>
    /// <param name="method">The method.</param>
    /// <remarks></remarks>
    public HttpVerb(String method)
        : base(method)
    {
    }

    #endregion

    #region Methods

    /// <summary>
    /// Gets the HttpMethod for WebDAV PROPFIND.
    /// </summary>
    /// <remarks></remarks>
    public static HttpMethod PropFind
    {
        get
        {
            return _PropFind;
        }
    }

    #endregion
}
Aug 25, 2011 at 4:28 PM

Thanks! It just looked like an enum in IntelliSense. Sorry, my fault!

Aug 25, 2011 at 4:32 PM

No apologies needed. Glad I could help. :D