美文网首页
[PHP高可用后端]②0--restful api

[PHP高可用后端]②0--restful api

作者: 子木同 | 来源:发表于2017-11-15 11:14 被阅读45次
    image.png image.png image.png image.png image.png image.png

    https://www.kancloud.cn/manual/thinkphp5/118035

    image.png

    准备工作

    image.png

    config.php

    <?php
    /**
     * Created by PhpStorm.
     * User: tong
     * Date: 2017/11/15
     * Time: 10:21
     */
    return[
      'default_return_type'=>'json',
    ];
    

    route.php

    <?php
    
    use  think\Route;
    
    Route::get('test', 'api/test/index');
    Route::put('test/:id', 'api/test/update');
    Route::delete('test/:id', 'api/test/delete');
    
    Route::resource('test','api/test');//查看手册对应方法
    //post =>api/test/ save
    

    Test.php

    <?php
    /**
     * Created by PhpStorm.
     * User: tong
     * Date: 2017/11/15
     * Time: 10:23
     */
    
    namespace app\api\controller;
    
    use think\Controller;
    
    class Test extends Controller
    {
    
        public function index()
        {
            return [
                'sgsg',
                'sgsgs',
            ];
        }
    
        public function update($id = 0)
        {
            //return $id;//http://singwa.com/test/100
    
            halt(input('put.'));//body提交
    
        }
    
        public function save()
        {
            return input('post.');
        }
    }
    

    Postman

    GET

    image.png

    PUT

    image.png image.png

    POST

    image.png

    相关文章

      网友评论

          本文标题:[PHP高可用后端]②0--restful api

          本文链接:https://www.haomeiwen.com/subject/gdbzmxtx.html