A RESTful API framework for the PHP language.
-
Create a raframework project name
raproj$ mkdir raproj && cd raproj
-
Create a
composer.jsonfile with the following contents:{ "require": { "raframework/raframework": "0.0.10" }, "autoload": { "psr-4": { "App\\": "App/" } } } -
Install the raframework by Composer
$ composer install
-
Make the resource classes directory
$ mkdir -p App/Resource
-
Create an
App/Resource/Users.phpfile with the following contents:<?php namespace App\Resource; use Ra\Http\Request; use Ra\Http\Response; // Define resource's class. class Users { // Define the resource's action. public function lis(Request $request, Response $response) { $data = 'List users...'; $response->withStatus(200)->write($data); } }
-
Create an
index.phpfile with the following contents:<?php require 'vendor/autoload.php'; // Define the routes. $uriPatterns = [ '/users' => ['GET'], // uri pattern => supported methods ]; // Create a raframework app with the routes given. $app = new Ra\App($uriPatterns); // Match the route, and set the resource's action correctly. $app->matchUriPattern() // Call the resource's action. // You should call matchUriPattern() before this. ->callResourceAction() // Send the response to the client. ->respond();
-
You may quickly test this using the built-in PHP server:
$ php -S localhost:8800
Going to http://localhost:8800/users will now display "List users...".
