我为API创建了逻辑,在其中我使用了一个函数来检查请求是否为POST。如果没有,它将返回一个错误。
from kivy.app import App
from kivy.uix.label import Label
class Playground(App):
def build(self):
hello_world_label = Label(text="Hello World!")
return hello_world_label
if __name__ == "__main__":
Playground().run()
看起来像这样:
AuthController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AuthController extends Controller {
private static function allowOneMethod($request, $allowed_method, $success_function){
$method = $request->method();
if ($method != $allowed_method){
return response()->json(['status' => 'error', 'message' => 'Method not Allowed.'], 405);
} else{
$success_function();
}
}
public function register(Request $request)
{
$this->allowOneMethod($request, 'POST', function() {
return response()->json(['status' => 'success', 'message' => 'It is a POST request.'], 200);
});
}
...
看起来像这样:
routes/api.php
但是我所看到的只是一个空白的答复。 可能是什么原因?
答案 0 :(得分:0)
您不会返回allowOneMethod()
方法
public function register(Request $request)
{
// you need to return your method value
return $this->allowOneMethod($request, 'POST', function() {
return response()->json(['status' => 'success', 'message' => 'It is a POST request.'], 200);
});
}