How to build a RESTful API?

前端 未结 7 1697
广开言路
广开言路 2020-11-27 09:43

The issue is this: I have a web application that runs on a PHP server. I\'d like to build a REST api for it.
I did some research and I figured out that REST api uses HTT

7条回答
  •  甜味超标
    2020-11-27 10:22

    In 2013, you should use something like Silex or Slim

    Silex example:

    require_once __DIR__.'/../vendor/autoload.php'; 
    
    $app = new Silex\Application(); 
    
    $app->get('/hello/{name}', function($name) use($app) { 
        return 'Hello '.$app->escape($name); 
    }); 
    
    $app->run(); 
    

    Slim example:

    $app = new \Slim\Slim();
    $app->get('/hello/:name', function ($name) {
        echo "Hello, $name";
    });
    $app->run();
    

提交回复
热议问题