Home > Article > Backend Development > restful
What I’m more confused about is that I learned that restful is only used for API design and following http rules. But how does the background implement the code related to the version number of the API? I haven't figured out whether to write one code for each version or some other method.
What I’m more confused about is that I learned that restful is only used for API design and following http rules. But how does the background implement the code related to the version number of the API? I haven't figured out whether to write one code for each version or some other method.
Different versions have different codes. For example:
api/
common/
controllers/
UserController.php
PostController.php
models/
User.php
Post.php
modules/
v1/
controllers/
UserController.php
PostController.php
models/
User.php
Post.php
Module.php
v2/
controllers/
UserController.php
PostController.php
models/
User.php
Post.php
Module.php
Reference: http://www.yiiframework.com/d...
As mentioned on the first floor
Or you can rewrite the routing or address rewriting according to the restful format, and then write the interface yourself, specify what data the fields of v1 and v2 are called respectively, and then return it
$v1=$_POST ['v1']?trim($_POST['v1']):null;
$v2=$_POST['v2']?trim($_POST['v2']):null;
$return=[];
$return['same']='same';
if($v1){$return['diffent']='v1';
if($v2){$return[' diffent']='v2';
echo json_encode($return);