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

2017-11-15  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读