如何使用REST Web服务在YII2中创建用户名和密码身份验证

I wish to create Web Services for each single task so that i do not replicated or rewrite code for same task for different platforms.

What you should do is have a REST file in your model with all the curl operations performed in it for various functions like get data and post data.After that use a object of this class to get and receive parameters if needed.

    $rest_obj = new RestService("web service URL", 'param1', 'param2');
    $rest_obj->requestName = 'webservice controller name';
    $rest_obj->requestData = '';
    $rest_obj->querydata = $data['request_params'];
    $rest_obj->requestType = "html";
    $rest_obj->responseType = "json";
    $rest_obj->getData();
    $fields_array = $rest_obj->response;  

If you do this then I think you can use this web service for n number of frontends. Web services are basically another Yii app with connection to the database and basically act as backend to a number of frontends.So my advice would be to create a controller and a model to fetch data from the db and connect it using the rest service I gave before and everything should work fine.