I would like to have (use) in my Yii2 application:
- a standard, SEO-like URLs, with
.html
at the end (thus'suffix' => '.html'
) and - API request (basing on very simple code) without this suffix.
So, to make my application being able to serve both http://127.0.0.1/app/site/index.html
-like URLs and http://127.0.0.1/uslabs/web/user/2
-like API calls.
It this possible? If so, how should I configure urlManager
component for this?
I went through “Quick Start” chapter in “RESTful Web Service” section, but it bring no help. They don’t use suffixes in examples given there. I’m stuck with the choice of either one or other scheme.
2
Answers
According to this Yii Forum post, what I'm trying to do is possible, but tricky and not encouraged.
API calls should be handled by a separate application. At the end of "Quick Start" part for API-like apps in Yii2 guide there's a suggestion:
Yii has a REST url router that you can use to associate with certain controllers, like this;
See the documentation for more details