Yii Framework Forum: REST API URL Rewrites with Module - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

REST API URL Rewrites with Module

#1 User is offline   scottreainc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 15-October 12

Posted 22 September 2017 - 03:33 PM

In my config I have the following:
'modules' => [
            'v0' => [
                'class' => 'app\modules\v0\Module',
            ],
            'v1' => [
                'class' => 'app\modules\v1\Module',
            ],
        ],


And I have the following URL manager:
'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing'=>true,
            'showScriptName' => false,
            
            'rules' => [
                ['class' => 'yii\rest\UrlRule', 'controller' => ['v0/object']],
                ['class'=>'yii\rest\UrlRule','controller'=>['v0/user'],'extraPatterns'=>['POST authenticate'=>'authenticate']],
                ['class' => 'yii\rest\UrlRule', 'controller' => ['v1/object','v1/user']], 
            ],
        ],



My actions are defined as follows:
actionCreate($name)
actionView/Update/Delete ($name, $id)


My Urls currently look like this (and work):
https://myapi.com/v0/objects?name=warehouse
https://myapi.com/v0/objects/12345?name=warehouse
https://myapi.com/v0/objects/6789?name=warehouse


But I need them to look like this:
https://myapi.com/v0/objects/warehouse
https://myapi.com/v0/objects/warehouse/12345


I have looked into url rewriting but just can't seem to figure out what I need to do / where it needs to go.

Could anyone shed some light on this please?

Thanks so much!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users