1. Compatibility goal: Adjust Feiliu’s response to match Tiao’s response specification (convert non-array field types to strings) while maintaining backward compatibility.
Note: If the version is absent from the request Headers, or if the version is present and greater than or equal to 2.1, all response fields will be strings. Otherwise, the original Feiliu fields are retained.
2. Call the API using Postman, requiring the API to respond according to the version 1.2.1 convention, where the field room_status is a numeric type, as shown in Figure 1.
Note: The 1 in V1 is the major version number, the 2 in version=2.1 is the minor version number, and the 1 in version=2.1 is the revision number.

3. Now, when the version is greater than or equal to 1.2.1, all response fields must be strings. To handle the minor version number, you can use the content negotiation feature provided by the contentNegotiator behavior. The contentNegotiator behavior can set the yii\web\Response::$acceptParams property when it determines which content types are supported. For example, if a request is sent with Accept: application/json; version=2.0, after content negotiation, yii\web\Response::$acceptParams will contain the value [‘version’ => ‘2.0’]. The code is shown in Figure 2.

4. Print $acceptParams, and the result is shown in Figure 3.

5. Based on the version information in acceptParams, write conditional code. The specific logic is: if the version is absent from the request Headers, or if the version is present and greater than or equal to 2.1, process it, as shown in Figure 4.

6. When the version is absent from the request Headers, the API responds according to the latest version specification, and all response fields are strings, as shown in Figure 5.

7. When the version is present in the request Headers but is less than 2.1, the API responds according to the specification for versions prior to 1.2.1, and the fields are not processed. In this case, the field room_status is a numeric type, as shown in Figure 6.

8. When the version is present in the request Headers and is greater than or equal to 2.1, the API responds according to the latest version specification, and all response fields are strings, as shown in Figure 7.

