我很苗条的框架,并试图建立一个基于json的API。所有我想问我怎么能保护我的API,因此只有那些应用程序将调用谁拥有用户名和密码的API函数使用用户名和密码proctect slim rest api
这是我的REST API的
require __DIR__ . '/vendor/autoload.php';
$app = new Slim\App();
//slim application routes
$app->get('/', function ($request, $response, $args) {
$response->withJson("Welcome Message", 201);
return $response;
});
$app->get('/orders/status/{status}', function ($request, $response, $args) {
return get_Orders($request, $response, $args);
});
$app->run();
function get_Orders($request, $response, $args){
if($args['status'] == "processing"){
$response->withJson("list of processing orders}", 200);
return $response;
}
else{
$response->withJson("Premission not guranted", 200);
return $response;
}
}
我只是建立一个简单的获取代码路线和它的工作,但我如何保证这一点,如果应用程序有一个有效的用户名和密码,那么只有它返回结果。
请问你举个例子api调用。应用程序如何调用上面列出的任何API函数 –
'curl --user root:t00r http:// localhost/api/something' –