Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

rest - RESTful URL: where should I put locale? example.com/en/page vs example.com/page?locale=en

I'm deciding how to organize URL and put locale into it. I have two choices:

  1. example.com/en/page
  2. example.com/page?locale=en -- Google way
  3. en.example.com/page -- isn't good because I'm using subdomains

From one side example.com/en/page looks better and more compact than example.com/page?locale=en. From other side we have two URLs example.com/en/page and example.com/ru/page for one resource with two representations. Of course in case example.com/page?locale=en we have two URLs for one resource too, but it is slightly more RESTful on my taste.

What's the best practice? What are you using and why?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Localization is part of Content-Negotiation in Restful API.

So my preferred way I would do it through headers. HTTP offers standard way of defining wanted language. Have a look at Accept-Language header.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...