PHP code example of craffft / contao-restful-webservices
1. Go to this page and download the library: Download craffft/contao-restful-webservices 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/ */
craffft / contao-restful-webservices example snippets
// systems/modules/mymodule/config/config.php
$GLOBALS['RESTFUL_WEBSERVICES']['ROUTING']['categories'] = array
(
// Define the webservice location (tional definition)
// You can use GET, PUT, POST and DELETE
'methods' => array('GET', 'POST'),
// Set '127.0.0.1',
),
// Restrict CORS access by ip addresses (optional definition)
'cors' => array
(
'192.168.1.180',
)
);
// systems/modules/mymodule/webservices/WebserviceCategories.php
namespace MyAppNamespace;
use \Haste\Http\Response\JsonResponse;
class WebserviceCategories extends \RESTfulWebservices\RESTfulController
{
public function get()
{
$arrData = array();
// Add "Hello World!" to the json output
$arrData['status'] = 'Hello World!';
// Send response
$objResponse = new JsonResponse();
$objResponse->setContent($arrData, JSON_PRETTY_PRINT);
$objResponse->send();
}
public function put()
{
// Code for PUT requests
}
public function post()
{
// Code for POST requests
}
public function delete()
{
// Code for DELETE requests
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.