Skip to content

multi-language versioned API #113

Closed
Closed
@jsbsantos

Description

@jsbsantos

Hello!

I just found out about this repo and was about to test it out on my current project but I can't seem to get thing to work as I want.

I had these routes defined, which I wanted to change so I could use URL path versioning.

config.Routes.MapHttpRoute(
    name: "DefaultApiLocalized",
    routeTemplate: "{language}-{culture}/api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

I expected that changing the routes as follows it would still work:

config.Routes.MapHttpRoute(
    name: "DefaultApiLocalized",
    routeTemplate: "{language}/api/v{version:apiVersion}/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/v{version:apiVersion}/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional, controller = "test" }
);

After reading a bit on past issues I found out that it's not supposed to work. However, I haven't found a way to make this work.

My question is, can I make these routes work:

/api/v1/my
en/api/v1/my

I have tried using this without success.

[RoutePrefix("{language?}api/v{version:apiVersion}/test")]

Thanks.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions