I am following the documentation.
I am trying to do POST request to my UserController that extends from ActiveController ( I want to create user ).
Using Postman extension for Google Chrome I fire this request:
POST /api/users?username=asd HTTP/1.1
Host: localhost
Authorization: Basic bmVuYWR6aXY6c2hvbmVaNDI0
Cache-Control: no-cache
Postman-Token: 4784adf7-5143-8ce5-b90f-0487eae9709f
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
I get this response:
[
{
"field": "username",
"message": "Username cannot be blank."
}
]
Few questions:
-
In my User model I have rules that specify that username can not be blank. But why is this rule fireing when I have sent something ?
-
If I create actionCreate() method in my UserController, and I return right at the start of method just to test, I can see that nothing happens. Yii totally ignores my code. How I am supposed to create my custom code ? I do not get it what is going on here.
-
If I extend UserController from yii\rest\Controller THEN I can see that my code in actionCreate is executing. But now comes my other troubles. How do I fire model validations and how to I return messages/errors as a response ? First how do I return status code ? And then, how to attach messages somewhere in the body ?
Is there any guide that explains how you can actually do these things ? Like how to implement fully functional endpoint using yii2. Because yii2 docs are NOT useful.
Thanks