Api First

The more and more projects starting to use this approach. When server provides only API. And all other work are performed by your device phone/browser. You do not need to render or return html it’s a work for client.

If you created created backend for some phone app you have to face with the same problems as me.

And what yii1/yii2 provides us.

  1. Good routes system. Some propositions
  • I remeber you guys (@yiiteam) wanted to implement nested routes. I think it would be very useful. What is the status of that stuff?

  • nice routes. I still need to extend default routes to something like this




  array('<controller>/list', 'pattern' => '<controller:[\w\-]+?>s', 'verb' => 'GET'),

// I don't have ability do the same for es- endings, i.e. entit(ies) specialt(ies) without extending core urlManager. 



  1. Request class
  • I already wrote that it would be nice to have ability automatically decode raw data.

Why you guys don’t want to introduce this feature in yii2 ?

  • How can I get POST data uploaded through request payload. Iphone guys like this feature ;)

  • How could I get all the POST data without accessing global $_POST. It’s a good practice to have read-only access to $_POST/$_GET from your controllers. So why we have

getPost($name,$defaultValue=null)

instead of

getPost($name=null, $defaultValue=null)

The same story with PUT. How can I get all the PUT data uploaded via POST (i.e. _method=PUT. This approach sometime useful for testing) in my controller.

$putData = $_POST;

or $putData = Yii::app()->request->getRestParams()

No this is REST, this put request PUT /user/123 and I wanna get put data.

$user->update($this->getPutData())

  • From provious note

What about adding shorthand for Controller

$this->getPost() VS Yii::$app->request->getPost()

Thoughts?

Thanks

  1. Not sure what nested routes are. It seems I wasn’t involved in the discussion you’re referring to. As for s/es you may try:



array('<controller>/list', 'pattern' => '<controller:[\w\-]+?>e?s', 'verb' => 'GET'),



  1. RAW data can contain anything. It can be JSON, XML, binary data so I don’t think we should try guessing it.

Getting request payload is simple:


\Yii::$app->request->getRawBody();

Now you can get whole set of request parameters as you’ve suggested: https://github.com/yiisoft/yii2/commit/cc5fe76c9ee421fe75d4e7bd8976ab109deee4a1

Not sure about adding controller shorthand…




array('<controller>/list', 'pattern' => '<controller:[\w\-]+?>e?s', 'verb' => 'GET'),



Will try.

Thanks for update

btw,


  array('<controller>/list', 'pattern' => '<controller:[\w\-]+?>s', 'verb' => 'GET'),

this can be written as


  'GET <controller:[\w\-]+?>s' => '<controller>/list',