Recently need to use PHP for mobile app to provide background API, see the domestic PHP Restful API relative less information, want to find a code to learn, PHP to get started only a few days, now need to know how to gracefully complete this API.
Reply content:
Recently need to use PHP for mobile app to provide background API, see the domestic PHP Restful API relative less information, want to find a code to learn, PHP to get started only a few days, now need to know how to gracefully complete this API.
If you meet two conditions:
Not very familiar with PHP;
API interface only need to provide a few simple;
Project time is relatively tight;
Well, I suggest you choose a little simpler framework that can be RESTful.
Why:
Not familiar with PHP case, it is difficult to grasp a large framework (such as: Phalcon, Laravel, YII, etc.);
For general developers, it is important to hand in homework on time;
Using PHP to implement RESTful API, the most important thing is: the implementation of the route, the parsing of HTTP requests (request), the good encapsulation of HTTP (response) response, and the good support of JSON format;
If so, I would recommend it to you:
Slim
Bullet
More lightweight small frames to search REST by themselves.
However, it is not to say that since you want to see other people's code to learn, then it should be with the purpose and doubt to be better. So it's a good idea to take a look at some RESTful API designs like GitHub, Mailgun, enchant, and so on.
In addition, you can refer to some of the network "best Practices", which is very much, this is not listed here. (You can take a look at this GitHub)
After having some understanding of REST, I think it will be more effective for you to see with your thoughts.
Finally, if you need a full-stack PHP framework (which takes some time) to implement the REST API, then you can choose, for example, YII, Laravel, and so on. But I still like Phalcon, and it's a simple tutorial to implement REST.
Non-Flarum, completely separated from front and back.
Back end to back end, written in Laravel.
Front end to the front end, written with Mithril.js.
Front-end and back-end based on JSONAPI communication.
Reference
Recommend a framework that is ideal for restful and microservices interfaces Phprs
Let you completely get rid of MVC in these scenarios.
Look at an example, this is a possible login interface implementation, only need to write the following code, invalid additional inheritance and configuration:
/** * 用户鉴权 * @path("/tokens/") */class Tokens{ /** * 登录 * @route({"POST","/accounts/"}) * @param({"account", "$._POST.account"}) 账号 * @param({"password", "$._POST.password"}) 密码 * @return({"body"}) 也通过body返回token,同cookie中的token相同, {"token":"xxx"} * @return({"cookie","token","$token","+365 days","/"}) 通过cookie返回token */ public function createTokenByAccounts($account, $password, &$token){ //验证用户 $token = ...; return ['token'=>$token]; } }
The framework defines routing and binding parameters through the @ comment, plus some useful advanced features: Dependency injection, Automation interface documentation, interface caching, and so on.
Although this framework looks relatively new on GitHub, it is now stable enough to be used in online environments