title: Http service meta:

  • name: description content: easyswoole,Http service
  • name: keywords content: swoole|swoole extension|swoole framework|easyswoole|Http service

Http service

The http component is a component that is automatically enabled when SERVER_TYPE is EASYSWOOLE_WEB_SERVER. It implements the controller connection pool, url parsing, and url routing rules. [http component demo] (https://github.com/easy-swoole/demo/tree/3.x-http)

Namespaces

We first need to register the namespace of the application directory in composer.json (the controller namespace defaults to App\HttpController)

  1. {
  2. "require": {
  3. "easyswoole/easyswoole": "^3.1"
  4. },
  5. "autoload": {
  6. "psr-4": {
  7. "App\\": "App/"
  8. }
  9. }
  10. }

Then update the composer

  1. Composer update

Convention specification

  • The class name and class file (folder) in the project are named, both are big hump, and the variable and class method are small hump.
  • In the HTTP response, echo $var in the business logic code does not output the $var content to the corresponding content. Please call the wirte() method in the Response instance.

Default controller

Create the App/HttpController/Index.php file:

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Tioncico
  5. * Date: 2019/4/11 0011
  6. * Time: 14:40
  7. */
  8. namespace App\HttpController;
  9. use EasySwoole\Http\AbstractInterface\Controller;
  10. class Index extends Controller{
  11. function index()
  12. {
  13. $this->response()->write('hello world');
  14. // TODO: Implement index() method.
  15. }
  16. }

Start easyswoole:

  1. Php easyswoole start

Access ip:9501, you can see the output “hello world”;