I am trying to implement the Yii2 RESTful Web Service API as described in the guide. I am trying it using the advanced application template. The problem is simply that all I get are 404 errors when I try to access the service. I wanted to start out trying something simple so I was simply going to use a country table and associated ActiveRecord class to try it out, here's the code:
This is in the components configuration in frontend/config/main.php :
'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ ['class' => 'yii\rest\UrlRule', 'controller' => 'country'], ], ], 'request' => [ 'parsers' => [ 'application/json' => 'yii\web\JsonParser', ] ] This is the code in frontend/controllers/CountryController.php :
namespace frontend\controllers; use yii\rest\ActiveController; class CountryController extends ActiveController { public $modelClass = 'common\models\Country'; } All of my ActiveRecord models like country are in common/models.
I used the following to try it:
curl -i -H "Accept:application/json" "http://myfrontendapp.loc/country" This is the output I get:
HTTP/1.1 404 Not Found Date: Fri, 31 Oct 2014 22:46:50 GMT Server: Apache Content-Length: 205 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL /country was not found on this server.</p> </body></html> I have spent many hours on this. I have adjusted the setting, read documentation, and alot more without any success. If anyone can see what the problem is please let me know, thanks!!