Creating a REST server

In the following recipe, we use an example that illustrates how you can build and set up RESTful APIs with minimal coding effort. This recipe will be reused in other recipes in this chapter.

Getting ready

  1. Create a new application by using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
  2. Create a migration for creating an article table with the following command:
    ./yii migrate/create create_film_table
    
  3. Then, update the just-created migration method, up, with the following code:
    public function up() { $tableOptions = null; if ($this->db->driverName === 'mysql') { $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; } $this->createTable('{{%film}}', ...

Get Yii2 Application Development Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.