Best way to return html

The restful service by default returns xml, json and html. When setting the format param in the url to return xml and json they work fine however, when setting it to html it throws an error similar to …response can’t be an array.

I have manged to get it to work by doing something like the following in my Rest controller

public function actions() {

    $formatParam = $this->behaviors()['contentNegotiator']['formatParam'];

    if (\Yii::$app->request->get($formatParam) == 'html') {

        //don't return default actions use defined ones below



    return parent::actions();


public function actionIndex() {

    return $this->render('index');


It would be nice if i could just set html and it would call whatever action instead of the default one. My question is what is the best way to support html while still keeping the other formats listed above?

What is the output in case of HTML?

The API returns a styled page that is rendered on a different domain. I have it working but the docs say it supports HTML by default and it appears it does not.

Where in the docs it’s pointed out that it supports HTML? That’s definitely a mis-guide to fix.

It does not since in order to render HTML framework needs a view template.

I’ll try and find it again as it was a couple of days ago or I could have just got it confused. Is what I’m doing the best way to handle HTML output via the restful service?

Yes. What you’re doing seems to be OK.