Search code examples
c#azureasp.net-web-api-routing

What's wrong with this route


Given the following:

namespace Foo.Controllers
{
    [RoutePrefix("api/route")]
    public class SnoconesFooBarController : BaseApiController
    {
        /// <summary>
        /// Asks for a new foo to be created to the given subnet with the specific bar named
        /// </summary>
        /// <param name="fooName"></param>
        /// <param name="uriString"></param>
        /// <returns></returns>
        [Route("newFoo/{fooName}")]
        public async Task<IHttpActionResult> PostNewFooForSpecificBar(string fooName, string uriString)
        {
        }
}

Why do I get a 404 when I try to post to:

http://localhost:4471/api/route/newFoo/test1

with the following payload:

"http://127.0.0.1"


Solution

  • FWIW, I fixed it by changing it to look like this:

     namespace Foo.Controllers
    {
        [RoutePrefix("api/route")]
        public class SnoconesFooBarController : BaseApiController
        {
            /// <summary>
            /// Asks for a new foo to be created to the given subnet with the specific bar named
            /// </summary>
            /// <param name="fooData"></param>
            /// <returns></returns>
            [Route("newFoo/")]
            public async Task<IHttpActionResult> PostNewFooForSpecificBar(FooRequestObject fooData)
            {
            }
    }
    

    And including all of the data I needed in the FooRequestObject