What is the simple design of REST in PHPREST architecture? REST (RepresentationalStateTransfer declarative State transfer) is a design and development method for network applications, which can reduce development complexity and improve system scalability. REST features: everything on the network is abstracted as a simple php rest architecture design
REST (Representational State Transfer declarative State Transfer) is a design and development method for network applications, which can reduce development complexity and improve system scalability.
- Everything on the network is abstracted as a resource)
- Each resource corresponds to a unique resource identifier)
- Operate resources through the general connector interface (generic connector interface;
- Operations on resources do not change the resource ID;
- All operations are stateless ).
- REST requests different service methods from the server through the HTTP request status, but the request address is the same. For example, to request an interface of http://xxxxx.com/user /,
- For example, the POST method generally provides new functions for data. if the client uses the POST method to request the above interface, it tells the server that it is a new operation.
- For example, the GET method is generally used to obtain data, because the GET method is the default method and does not change the data, so it is generally used to obtain data and request the above interface through the GET method, is to get user data
- For example, the PUT method is generally an update operation, which tells the server to update user information.
- For example, the DEL method is generally a delete operation.
- Through the request method in HTTP 4, four different requests can be generated on the same interface address, which provides great help for interface scalability.
- Simple rest php code implementation:
/*** DEMO * @ author zhuli */class indexController extends Controller {public $ initphp_list = array ('test', 'User '); // Action whitelist public $ isRest = array ('user'); // request index. php? C = index & a = user interface, using different CURL request states public function run () {$ curl = $ this-> getLibrary ('curl '); $ a = $ curl-> put ('http: // 10.9.11.1/initphp_32/demo/www /? C = index & a = user', array ('username' => 'Hello'); print_r ($ );} // when the request method is GET, public function user_get () {echo 'get';} // POST method public function user_post () {$ username = $ this-> controller-> get_gp ('username', 'P'); echo $ username; echo 'get';} // PUT public function user_put () {$ username = $ this-> controller-> get_gp ('username', 'u'); echo $ username; echo 'put';} // DEL public function user_del () {$ username = $ this-> controller-> get_gp ('username', 'D'); echo $ username; echo 'Del ';}}
Reference: Baidu and InitPHP framework REST implementation