-
Notifications
You must be signed in to change notification settings - Fork 712
multi-language versioned API #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Glad you found the project. Welcome! I'm a little confused. Are you using attribute or convention-based routing? I see parts of both. I strongly recommend using one or the other. You may go cross-eyed otherwise. There are also some limitations in Web API's routing when both are used. For a convention-based route, this should work: config.Routes.MapHttpRoute(
name: "DefaultApiLocalized",
routeTemplate: "{language}/api/v{version:apiVersion}/{controller}/{id}",
defaults: new { language = "en", id = RouteParameter.Optional }
); I don't recall ever using a default value in a route prefix, but I believe for an attribute-based route, this should work: [ApiVersion( "1.0" )]
[RoutePrefix("{language=en}/api/v{version:apiVersion}/test")]
public class TestController : ApiController
{
[Route]
public IHttpActionResult Get() => Ok();
} I also noticed in your route prefix that you were missing the I haven't tried these myself, but I suspect they may work. Give it a whirl and let me know. |
You're right, it came out a bit confusing. What i meant was that I tested both configurations, but I'm not using them both. Either way, your suggestions didn't work. It may have something to do with my configuration, I don't know, but we've moved the language parameter to the Accept-Language HTTP header. Thanks. |
Sounds good. I think you made the right decision. The Accept-Language header will give you a lot more flexibility in requests because it supports multiple values with quality. You'll have the option to support language fallback without any changes to the API. :) |
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.
I expected that changing the routes as follows it would still work:
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:
I have tried using this without success.
Thanks.
The text was updated successfully, but these errors were encountered: