PHP code example of bulton-fr / bfw-api

1. Go to this page and download the library: Download bulton-fr/bfw-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bulton-fr / bfw-api example snippets


return [
    'urlPrefix' => '/api',
    'useRest' => true,
    'useGraphQL' => false
];

return [
    'routes' => [
       '/books/{bookId:\d+}' => [
            'className' => 'Book',
            'method'    => ['GET', 'POST']
        ],
    ]
];

namespace Api;

class Book extends \BfwApi\Rest
{
    public function getRequest()
    {
        $returnedDatas = (object) [
            'elements' => (object) [
                'elemA' => [
                    0 => (object) [
                        'elemB' => 'Foo',
                        'elemC' => 'Bar'
                    ],
                    1 => (object) [
                        'elemB' => 'Foz',
                        'elemC' => 'Baz'
                    ]
                ]
            ]
        ];
        
        $this->sendResponse($returnedDatas);
    }
    
    public function postRequest()
    {
        $modele = new \Modeles\Books;
        //We consider to have some checks of the datas here.
        $status = $modele->updateBooks($this->datas);
        
        $response = (object) [
            'status' => $status,
        ];
        $this->sendResponse($response);
    }
}