If the action points to a file with a php file extension Canpi simply includes this file. In the following an example implementation:
If the action contains an http or https url the request gets forwarded to the defined endpoint. Canpi automatically adds some additional headers to the request which may be used by the endpoint i.e.:
If the action points to a simple file Canpi will simply forward the content to the client. This is helpful if you want to build fast and sample API with dummy responses.
If the action string is a PHP class Canpi tries to autoload this class through composer. The class must implement the Canpi\Engine\ActionInterface. This is the most advanced solution since it is also possible to access services from the DI container. In the following an example implementation:
Please take a look at the recipes section of our website, there we have example code to complete a specific task i.e. send a HTTP request or query data from a database.
Inside an action you can use the connector to obtain a configured connection. The following list contains connection classes which you can use. Note some connections depend on PHP extensions or other client libraries, you have to install the fitting adapter in order to use the connection. Take a look at the adapter page for an overview of available adapters.
HTTP
Uses the Guzzle library to send HTTP requests.
- Class
-
| Canpi\Adapter\Http\Connection\Http |
- Return
-
- Website
- http://docs.guzzlephp.org/en/latest/
Config
HTTP base url
Optional username for authentication
Optional password for authentication
Optional HTTP proxy
AMQP
Provides a client to send messages to a RabbitMQ.
- Class
-
| Canpi\Adapter\Amqp\Connection\Amqp |
- Return
-
| PhpAmqpLib\Connection\AMQPStreamConnection |
- Website
- https://github.com/php-amqplib/php-amqplib
config
The IP or hostname of the RabbitMQ server
The port used to connect to the AMQP broker. The port default is 5672
The login string used to authenticate with the AMQP broker
The password string used to authenticate with the AMQP broker
The virtual host to use on the AMQP broker
Beanstalk
Provides a client to send messages to a Beanstalkd.
- Class
-
| Canpi\Adapter\Beanstalk\Connection\Beanstalk |
- Return
-
- Website
- https://github.com/pda/pheanstalk
config
The IP or hostname of the Beanstalk server
Optional the port of the Beanstalk server
Elasticsearch
Connects to a Elasticsearch database using the official PHP library.
- Class
-
| Canpi\Adapter\Elasticsearch\Connection\Elasticsearch |
- Return
-
- Website
- https://github.com/elastic/elasticsearch-php
config
Comma separated list of elasticsearch hosts i.e.
| 192.168.1.1:9200,192.168.1.2 |
Memcache
Uses the native PHP memcached extension to connect to a memcache server.
- Class
-
| Canpi\Adapter\Memcache\Connection\Memcache |
- Return
-
- Website
- http://php.net/manual/de/book.memcached.php
config
Comma seperated list of [ip]:[port] i.e.
| 192.168.2.18:11211,192.168.2.19:11211 |
Neo4j
Connects to a Neo7j graph database using the official PHP library.
- Class
-
| Canpi\Adapter\Neo4j\Connection\Neo4j |
- Return
-
| GraphAware\Neo4j\Client\ClientInterface |
- Website
- https://github.com/graphaware/neo4j-php-client
config
URI of the connection i.e. http://neo4j:password@localhost:7474
SOAP
Provides a client to send SOAP requests.
- Class
-
| Canpi\Adapter\Soap\Connection\Soap |
- Return
-
- Website
- http://php.net/manual/de/class.soapclient.php
config
Location of the WSDL specification
Required if no WSDL is available
Required if no WSDL is available
Optional SOAP version
- 1 = SOAP 1.1
- 2 = SOAP 1.2
Optional username for authentication
Optional password for authentication