PHP code example of blacknell / restapi-service

1. Go to this page and download the library: Download blacknell/restapi-service 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/ */

    

blacknell / restapi-service example snippets


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule myapi/v1/(.*)$ myapi/v1/api.php?request=$1 [QSA,NC,L]
</IfModule>

{
    "description": "Between sunrise and sunset yesterday",
    "sunrise": {
        "date": "2019-01-07 08:00:56.000000",
        "timezone_type": 3,
        "timezone": "Europe\/London"
    },
    "sunset": {
        "date": "2019-01-07 16:15:44.000000",
        "timezone_type": 3,
        "timezone": "Europe\/London"
    }
}

	public function __construct($request, \Monolog\Logger $logger = null)
	{
		header('Access-Control-Allow-Origin: http://myclient.com');
		parent::__construct($request, $logger);
	}


	protected function isAuthenticated()
	{
		$headers=getallheaders();
		if($headers['Authentication-Token'] !== 'xxx') {
			return false;
		} else {
			return parent::isAuthenticated();
		}
	}