Is there any good open source project or instance code for PHPRestfulAPI?

Source: Internet
Author: User
Recently, we need to use PHP to provide backend APIs for mobile apps. We can see that there are few documents related to PHPRestfulAPI in China. If you want to learn a piece of code, PHP is only a few days old, now you need to know how to complete this API elegantly. Recently, we need to use PHP to provide backend APIs for mobile apps. We can see that there are few documents related to PHP Restful APIs in China. To learn a code, we can only get started with PHP for a few days, now you need to know how to complete this API elegantly.

Reply content:

Recently, we need to use PHP to provide backend APIs for mobile apps. We can see that there are few documents related to PHP Restful APIs in China. To learn a code, we can only get started with PHP for a few days, now you need to know how to complete this API elegantly.

If you meet the following two conditions:

  1. I am not very familiar with PHP;

  2. Only a few simple APIs are required;

  3. Project time is relatively tight;

So, I suggest you choose a simple small RESTful framework.

Why:

  1. If you are not familiar with PHP, it is difficult to grasp a huge framework (such as Phalcon, Laravel, YII, and so on) at once );

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

  3. Using PHP to implement RESTful APIs, the most important thing is: Implementation of routing, resolution of HTTP requests, good encapsulation of HTTP response, and good support of JSON format;

If so, I will recommend it to you:

  1. Slim

  2. Bullet

More lightweight small frameworks search for REST by themselves.

However, it cannot be said that since we want to learn from other people's code, it should be better with the purpose and question. We recommend that you first look at the excellent design of some RESTful APIs, such as GitHub, Mailgun, and Enchant.

In addition, you can also refer to some "best practices" on the network, which is a lot more and will not be listed here. (Check GitHub at a Glance)

After having some knowledge of REST, I think it will get twice the result with my thoughts.

Finally, if you need a full-stack PHP framework (which takes some time to grasp) to implement REST APIs, you can also choose, such as YII and Laravel. But I still like Phalcon most. It is also a simple tutorial to implement REST.

Non-Flarum does not belong to and is completely separated from the frontend and backend.

  • The backend belongs to the backend and is written in Laravel.

  • The front end belongs to the front end and is written in Mithril. js.

Frontend and backend communication are based on jsonapi.

Reference
  • Flarum technical Architecture

We recommend a framework phprs suitable for RESTful and microservice interfaces.

Let you get rid of MVC in these scenarios.

Let's take a look at the example. This is a possible login interface implementation. You only need to write the following code. The additional inheritance and configuration are invalid:

/*** User authentication ** @ path ("/tokens/") */class Tokens {/*** login * @ route ({"POST ", "/accounts/"}) * @ param ({"account", "$. _ POST. account "}) account * @ param ({" password "," $. _ POST. password "}) the password * @ return ({" body "}) also returns the token through the body, which is the same as the token in the cookie, {" token ": "xxx"} * @ return ({"cookie", "token", "$ token", "+ 365 days ","/"}) return token */public function createTokenByAccounts ($ account, $ password, & $ token) through cookie {// verify the user $ token = ...; return ['Token' => $ token];}

The Framework defines routing and binding parameters through @ annotation. In addition, there are some useful advanced features: dependency injection, automated interface documentation, interface caching, and so on.
Although this framework looks quite new on github, it is actually very stable and can 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.