Blesta Source Documentation

Api extends AppController

A RESTful API system for interacting with the Blesta backend.

All public model methods are accessible. Plugin models may also be invoked by simply formatting the model as Plugin.Model (e.g. /api/plugin.model/method.format). Supports XML, JSON, and PHP as format types.

Table of Contents

Constants

BAD_REQUEST
FORBIDDEN
INTERNAL_ERROR
MAINTENANCE_MODE
NOT_FOUND
OK
UNAUTHORIZED
UNSUPPORTED_FORMAT

Properties

$errors
$format
$formats
$method
$model
$model_name
$request_method

Methods

index() The backbone of the API. Processes the request for the desired resource
preAction() Verify that the request is properly formatted, and ensure the requester is authorized.
authenticate() Attempt to authenticate the user
encode() Encodes the data given into the desired output format
getAuthMode() Returns the authentication mode being used by the user
getHeaders() Returns all the incoming request headers
matchParameters() Matches the given parameters with those defined in the requested method.
response() Outputs the response and data of the current Request in the desired format
Constants

BAD_REQUEST

public mixed BAD_REQUEST = 'The request cannot be fulfilled due to bad syntax.'

FORBIDDEN

public mixed FORBIDDEN = 'The requested resource is not accessible.'

INTERNAL_ERROR

public mixed INTERNAL_ERROR = 'An unexpected error occured.'

MAINTENANCE_MODE

public mixed MAINTENANCE_MODE = 'The requested resource is currently unavailable due to maintenance.'

NOT_FOUND

public mixed NOT_FOUND = 'The requested resource does not exist.'

OK

public mixed OK = 'OK'

UNAUTHORIZED

public mixed UNAUTHORIZED = 'The authorization details given appear to be invalid.'

UNSUPPORTED_FORMAT

public mixed UNSUPPORTED_FORMAT = 'The format requested is not supported by the server.'
Properties

$errors

private mixed $errors = \false

An array containing all errors set by the model, false if no errors set

$format

private string $format = 'json'

The current output format

$formats

private static array<string|int, mixed> $formats = ['json' => 'application/json', 'php' => 'text/plain', 'xml' => 'application/xml']

The available output formats

$method

private string $method

The method of the model to execute

$model

private string $model

The full model string (e.g. Plugin.Model)

$model_name

private string $model_name

The model name to load (e.g. Model)

$request_method

private string $request_method = 'POST'

The request method (POST, GET, PUT, DELETE)

Methods

index()

The backbone of the API. Processes the request for the desired resource

public index() : mixed

preAction()

Verify that the request is properly formatted, and ensure the requester is authorized.

public preAction() : mixed

authenticate()

Attempt to authenticate the user

private authenticate() : bool
Return values
bool

True if the user is valid, false otherwise

encode()

Encodes the data given into the desired output format

private encode(array<string|int, mixed> $data) : string
Parameters
$data : array<string|int, mixed>

the Data to encode into $this->format

Return values
string

The encoded data based on the format given in $this->format

getAuthMode()

Returns the authentication mode being used by the user

private getAuthMode() : string
Return values
string

The authentication mode being used by the user

getHeaders()

Returns all the incoming request headers

private getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array containing all the headers

matchParameters()

Matches the given parameters with those defined in the requested method.

private matchParameters([mixed $parameters = null ]) : array<string|int, mixed>
Parameters
$parameters : mixed = null
Return values
array<string|int, mixed>

An array of parameters to be passed to the requested method.

response()

Outputs the response and data of the current Request in the desired format

private response(string $response[, mixed $data = null ][, bool $encode = true ]) : mixed
Parameters
$response : string

The server response

$data : mixed = null

The data to be output (will be encoded into the appropriate format automatically)

$encode : bool = true

True to automatically encode the given data, false otherwise.

Tags
subpackage

app.controllers

copyright

Copyright (c) 2010, Phillips Data, Inc.

license

http://www.blesta.com/license/ The Blesta License Agreement

link

Blesta


        
On this page

Search results