Api-php write a restful interface?

Source: Internet
Author: User
Keywords rest-api api php
Tags php write
Want to implement a simple Restfull API with PHP
Find PHP is not nodejs as easy to control routing rules, routing is controlled by Apache

Can you give me some advice? How do I control routing to implement restful APIs?

Reply content:

Want to implement a simple Restfull API with PHP
Find PHP is not nodejs as easy to control routing rules, routing is controlled by Apache

Can you give me some advice? How do I control routing to implement restful APIs?

Http://frapi.github.io/developing/creati ... Generate API interfaces directly in the background

No rules for routing must be given to Apache! You can implement a restful interface by assembling all requests to the unified portal, and then parsing the URI and method of the request and dispatching it to the corresponding interface API program. Many PHP frameworks are also developed specifically for restful, such as slim. And most of the PHP framework also supports restful routing, and the implementation looks at their code.

Yii/laravel Frame

You can use such redirection rules to forward files that cannot be found to index.php

Options +FollowSymLinksRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]

And then you can define your own routes.

Try Laravel and you'll find that it's very similar to express, recommended with Laravel

What you need is a PHP routing controller, Slim is really good.

All frameworks are freely customizable routes, such as CI and thinkphp, which simply bind the route and the corresponding controller by default.

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