I want to use php to implement a simple restfullapi and find that php is not as easy to control routing rules as nodejs. The routing is controlled by apache and can give some suggestions. How can I control the routing to implement restfulapi? I want to use php to implement a simple restfull api
It is found that php is not as easy to control routing rules as nodejs. The routes are controlled by apache.
Can you give me some suggestions? How do I control routes to implement restful APIs?
Reply content:
I want to use php to implement a simple restfull api
It is found that php is not as easy to control routing rules as nodejs. The routes are controlled by apache.
Can you give me some suggestions? How do I control routes to implement restful APIs?
Http://frapi.github.io/developing/creati... generate api interface directly with the background
No route is required to be handed over to Apache! You can aggregate all requests to a unified portal, parse the request URI and Method, and schedule the requests to the corresponding Api program. In the same way, you can implement Restful interfaces. Many PHP frameworks are specially developed for Restful, such as Slim. In addition, most PHP frameworks support Restful routing. You can see their code for specific implementations.
Yii/Laravel framework
You can use this redirection rule to forward files that cannot be found to index. php.
Options +FollowSymLinksRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]
Then you can define your own Routes.
If you try laravel, you will find it is very similar to express. laravel is recommended.
What you need is a php route controller, and slim is really good.
All the frameworks can customize the routes. For example, ci and thinkphp only bind the routes to the corresponding controllers by default.