Endpoints

Introduction

Endpoints represent your path relative to the Collection or Resource it's attached to. Allowed roles applied to it's Collection or Resource as well as the expected POST data format can be overriden.

use PhalconRest\Api;
use PhalconRest\Api\Collection;
use PhalconRest\Api\Endpoint;

$api = new \PhalconRest\Api;

$api->collection(Collection::factory('auth')
  ->handler(AuthController::class)
  ->allow(\UserRoles::UNAUTHORIZED)
  ->endpoint(Endpoint::post('/login', 'login'))
);

Provides you with a POST endpoint with /auth/login as path. The login method on AuthController will be used to handle this endpoint.

Method Listing

handlerMethod()

Name of controller-method to be called for the endpoint

name()

Set name for the endpoint (will be used to generate documentation)

getName()

Returns name for the endpoint

description()

Set description for the endpoint (will be used to generate documentation)

getDescription()

Returns description for the endpoint

getHttpMethod()

Returns the HTTP method for the endpoint

exampleResponse()

Set a example response that will be rendered in the documentation

getExampleResponse()

Returns the example response

getPath()

Returns the path of the endpoint, relative to the collection/resource

postedDataMethod()

Set one of the method constants defined in PhalconRest\Constants\PostedDataMethods

getPostedDataMethod()

Returns the PostedDataMethod being used

expectsPostData()

Will set the PostedDataMethod to PostedDataMethods::POST

expectsJsonData()

Will set the PostedDataMethod to PostedDataMethods::JSON_BODY

allow()

Allows access to this endpoint for the roles with the given names. These will override those applied on the Collection or Resource.

deny()

Denies access to this endpoint for the roles with the given names. These will override those applied on the Collection or Resource.

getAllowedRoles()

Returns the allowed roles.

getDeniedRoles()

Returns the denied roles.

Factory Methods

Standard

factory()

Endpoint::factory('/books');

Returns a default endpoint.

get()

\PhalconRest\Api\Endpoint::get('/books');

Returns pre-configured GET endpoint

post()

Endpoint::post('/books');

Returns pre-configured POST endpoint

put()

Endpoint::put('/books');

Returns pre-configured PUT endpoint

delete()

Endpoint::delete('/books');

Returns pre-configured DELETE endpoint

Endpoint::head('/books')

Returns pre-configured HEAD endpoint

options()

Endpoint::options('/books');

Returns pre-configured OPTIONS endpoint

patch()

Endpoint::patch('/books');

Returns pre-configured PATCH endpoint

CRUD

These pre-configured endpoints are by default part of CRUD Resources that have either a PhalconRest\Mvc\Controllers\CrudResourceController attached or a handler of your own.

all()

Endpoint::all();

Using this factory will create a GET endpoint with / as path.

Returns all items

find()

Endpoint::find();

Using this factory will create a GET endpoint with /{id} as path.

Returns the item identified by {id}

create()

Endpoint::create();

Using this factory will create a POST endpoint with / as path.

Creates a new item using the posted data

update()

Endpoint::update();

Using this factory will create a PUT endpoint with /{id} as path.

Updates an existing item identified by {id}, using the posted data

remove()

Endpoint::remove();

Using this factory will create a DELETE endpoint with /{id} as path.

Removes the item identified by {id}