Skip to content
Advertisement

Yii2: Rest POST Request Parameters not arriving

Good morning,

I dont get any further in this Topic so i am writing a Question here.

First of all i created a DB Table with Data from the Tutorial: https://www.yiiframework.com/doc/guide/2.0/en/start-databases

Then i created a Rest Controller from that Tutorial with the Data above: https://www.yiiframework.com/doc/guide/2.0/en/rest-quick-start

The first example GET Request from the Tutorial works fine and gives me all of the data from the DB. My Request URL: http://XX.X.X.12:XX90/country/

Now we come to my Error when trying to create a new Country in the DB via a POST Request. When using the CURL Command from underneath the Tutorial with my Test-Data i get following error:

JavaScript

My standard logging from rest api says that the POST Var is empty, but why? I also tested sending POST Request via a Tool (Postman) but i get the same error.

JavaScript

My Model:

JavaScript

My Controller:

JavaScript

My CURL Request:

JavaScript

My web.php Config:

JavaScript

Suggestions?

Advertisement

Answer

You need to declare validation rules for working with the Rest API

Thanks to @Bizley

My Country Model now:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement