Is there an open source project or instance code for a better php Restful API?

Source: Internet
Author: User
Tags php framework
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:

    1. Not very familiar with PHP;

    2. API interface only need to provide a few simple;

    3. Project time is relatively tight;

Well, I suggest you choose a little simpler framework that can be RESTful.

Why:

    1. Not familiar with PHP case, it is difficult to grasp a large framework (such as: Phalcon, Laravel, YII, etc.);

    2. For general developers, it is important to hand in homework on time;

    3. 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:

    1. Slim

    2. 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

    • Flarum Technical Architecture Architecture

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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.