0

Lets say I have the following ApiController and method:

[RoutePrefix("configs")]
public class FullConfigController : ApiController
{
    [Route("{ID}")]
    [HttpGet]
    public string GetConfig(Guid ID)
    {
        return "my config data";
    }
}

It's a simple GET method designed to return some basic configuration data based on that configurations ID which is represented by a GUID. My intention is to call the end point as such

http://<url>/configs/70C55EDA-9671-4D75-A715-0835DB8AC2E3

However this does not route through the engine. Yet this

http://<url>/configs?ID=70C55EDA-9671-4D75-A715-0835DB8AC2E3

does. How do I specify that I do not want a query string parameter here but a URL segment parameter instead?

EDIT: Request for the WebApiConfig

public class RouteTemplateVariables
{
    public const string PluginRoot = "PluginRoot";
    public const string CorePluginRoot = "CorePluginRoot";
    public const string AdditionalSegments = "AdditionalSegments";
}

public static class WebApiConfig
{
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    public static void Register(HttpConfiguration config)
    {
        log.Info("WebApiConfig.Register()");

        // Attribute routing
        config.MapHttpAttributeRoutes();

        // Convention-based routing.
        config.Routes.MapHttpRoute(
            name: "PluginApi",
            routeTemplate: "api/plugin/{" + RouteTemplateVariables.PluginRoot + "}/{*" + RouteTemplateVariables.AdditionalSegments + "}",
            defaults: new { AdditionalSegments = RouteParameter.Optional }
        );

        config.Routes.MapHttpRoute(
            name: "CoreApi",
            routeTemplate: "api/{" + RouteTemplateVariables.CorePluginRoot + "}/{*" + RouteTemplateVariables.AdditionalSegments + "}",
            defaults: new { AdditionalSegments = RouteParameter.Optional }
        );
    }
}
Ultratrunks
  • 2,464
  • 5
  • 28
  • 48
  • 1
    Did you try to specify parameter's type? something like this {ID:guid} – Alcruz Sep 14 '17 at 00:54
  • Do you have multiple HttpGet methods, if not you can remove the [Route("{ID}")] because it gets bind by convention. – Jean Jimenez Sep 14 '17 at 01:53
  • I had not tried specifying the parameter type but I just did and it apparently had no effect, I have one method only, MapHttpAttributesRoutes has been enabled and I've edited the question to include that now. – Ultratrunks Sep 14 '17 at 17:24

0 Answers0