Rest API

Rest API usage

Active Rest and basic auth

Open the templates config file and add:

// Add basic auth logins.
define("BASIC_AUTH", [
	"[USERNAME_1]" => '[PASSWORD_1]',
	"[USERNAME_2]" => '[PASSWORD_2]'
]);

// Add scopes and will specify which api that should be enabled 
define("BASIC_AUTH_SCOPES", ["pages", "products"]);

Se API calls documentation »

Create Basic Auth

1. Add "basicAuth" Trait to your Modal

namespace app\repository\rest;

class modal extends \template\modals\pageModal {
	use \app\traits\basicAuth;

	
	function __construct($request, $url, $headers, $session) {
		parent::__construct($request, $url, $headers, $session);
	}
}

2. Create controller, Basic Auth, validation and set json data

function __construct($modal) {
	parent::__construct($modal);
	
	$this->modal()->json()->add("status", $this->modal()->headers()->status());  // Set header status validation to json
	$this->modal()->basicAuthScopeValidation("pages");  // Add scope validation to app
}

function get() {
	$auth = $this->modal()->basicAuth();
	if($auth && $auth->validate()) {
		parent::get();
		$this->modal()->json()->add("data", $this->modal()->page); // Add a data to json
	}
}

Complete method list

use \app\traits\basicAuth;
Add Basic Auth validation
@return bool
basicAuth()
Add scope validation
@param string $key required scope to call API
basicAuthScopeValidation($key)