Q:

Yii 2 rest service url management

I just want to offer a Rest api for my Yii 2 application.
I saw the guide and in this default case everything clear.
But I want some "tricky" path and url things and I don't know how to achieve them.
First thing, my api controllers are outside my web root, like this:
- "Complete Application folder"
---- "Api"
-------- "controllers"
---- "Web root"
-------- "assets"
-------- "components"
-------- "config"
-------- "..."
Second thing is, I want my urls under the prefix "Api", like this:
http://www.myapp.de/Api/Model
Can someone help me to achieve this?
Kind regards

A:

you can achieve this if you chooses this kind of folder structure 
if you choose Yii 2 advanced application template
you have to create an application like frontend or backend, what you have to do is create another directory call 'api' same as backend or frontend, and it'll contain folder structure same as backend|frontend except assets, views, widgets etc. (v1 for versions)
api

-config
-modules
--v1
---controllers
---models
-runtime
-tests
-web

backend
common
console
environments
frontend

if you choose Yii 2 basic application template to develop rest api, it's posible. create module call 'api' and create a sub directory call 'v1' as sub-module. (v1 for versions)
(Yii doc -A module may consist of sub-modules.)(GiovanniDerks - backend sub-modules)
-modules
--api
---v1
----controllers
----models

There is an advantage of using one of these folder structure, because you don't have to worry about route much. 
https://domain.com/api/v1/products

Here is good example/project for RESTful API with advance template 
Setup RESTful API in Yii2(budiirawan)
Here is an ebook for REST API standards 
REST API Desing Rulebook

