Download the PHP package nolte/wp-endpoint without Composer
On this page you can find all versions of the php package nolte/wp-endpoint. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nolte/wp-endpoint
More information about nolte/wp-endpoint
Files in nolte/wp-endpoint
Package wp-endpoint
Short Description wp-endpoint
License MIT
Homepage https://github.com/wearenolte/wp-endpoint
Informations about the package wp-endpoint
WP Endpoint
Class that makes the process to create a new WordPress endpoint more easily.
By default the endpoint are under the leen namespace with the version number 1 this data can be overwritten using any of the filters specified below.
The class provides a set of defined methods and mechanism to register a new endpoint, wich makes the process of define a new endpoint pretty straightforward.
Getting Started
The easiest way to install this package is by using composer from your terminal:
Or by adding the following lines on your composer.json
file
This will download the files from the packagist site and set you up with the latest version located on master branch of the repository.
After that you can include the autoload.php
file in order to
be able to autoload the class during the object creation.
Usage
After you added the dependency on your module you need to create a new class that defines your endpoint for example:
On this class you have:
init
or any other name you want to expose is a public static method that always have the same signature in order to execute the code that runs the new endpoint.endpoint_callback
, By default you have one method that allow you to define the response of the GET request to the endpoint, GET is the default HTTP Verb.endpoint_args
, Same asendpoint_callback
, is the callback by default that allow you to define if the endpoint allow parameters and how are going to be used.endpoint_options
, if you want to specify a new set of HTTP verbs andor rewrite the default endpoint options, you only need to return an array with the parameters that are required for the endpoint.
For instance to define a new slug parameter with a different HTTP verb and reuse the default get params. You only need to define as follows
parent::endpoint_options
is going to return the default options defined on Endpoint
class if you don't want to redeclare the options for a GET request.
Collections
There is also an abstract class available for collections.
Filters
nolte_endpoints_api_namespace
, This allow you to overwrite the default namespace used on the API definition.nolte_endpoints_api_version
, This filter allow you to change the version number of the API.nolte_endpoints_data_${api}
, where${api}
is the name of your endpoint for instance in the case above:nolte_endpoints_data_customEndpoint
.nolte_endpoints_collection_item
, to do custom formatting for collection items.