### Successful OPTIONS Response Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md Example of a successful HTTP 200 OK response to an OPTIONS request, indicating the allowed methods via the Allow header. ```HTTP HTTP/1.1 200 OK Allow: GET ``` -------------------------------- ### GET Request for JSON Data Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md Demonstrates a GET request to the /ping endpoint with an Accept header set to application/json, expecting a JSON response. ```HTTP GET /ping HTTP/1.1 Accept: application/json ``` -------------------------------- ### OPTIONS Request for Allowed Methods Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md Demonstrates an OPTIONS request to the /ping endpoint to discover which HTTP methods are allowed. ```HTTP OPTIONS /ping HTTP/1.1 ``` -------------------------------- ### Install Laminas API Tools using Git clone and Composer install Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/installation.md Installs the Laminas API Tools skeleton project by first cloning the repository using Git, then navigating into the project directory and installing dependencies with Composer. ```console git clone https://github.com/laminas-api-tools/api-tools-skeleton.git # optionally, specify the directory in which to clone cd path/to/install composer install ``` -------------------------------- ### Successful JSON Response Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md Example of a successful HTTP 200 OK response with a JSON content type, containing an acknowledgment. ```HTTP HTTP/1.1 200 OK Content-Type: application/json { "ack": 1396560875 } ``` -------------------------------- ### POST Request with JSON Data Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md Illustrates a POST request to the /ping endpoint, specifying application/json for both Accept and Content-Type headers, and including a JSON payload. ```HTTP POST /ping HTTP/1.1 Accept: application/json Content-Type: application/json { "timestamp": 1396560875 } ``` -------------------------------- ### HTTP GET Request for RPC Service Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md This snippet shows a standard HTTP GET request to a '/ping' endpoint, with the 'Accept' header set to 'text/html'. This is used to test the RPC service and demonstrate how the server responds to different content type requests. ```http GET /ping HTTP/1.1 Accept: text/html ``` -------------------------------- ### Console Help Reporting Example Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md Illustrates how to get help for individual commands by executing 'script help '. Displays command usage and detailed help information. ```console $ ./script.php help self-update Builder, version 1.1.3 Usage: self-update Help: When executed via the Phar file, performs a self-update by querying the package repository. If successful, it will report the new version. ``` -------------------------------- ### OPTIONS /ping Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md This endpoint can be used to query the allowed HTTP methods for the /ping endpoint. ```APIDOC ## OPTIONS /ping ### Description Retrieves information about the allowed HTTP methods for the /ping endpoint. ### Method OPTIONS ### Endpoint /ping ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```HTTP OPTIONS /ping HTTP/1.1 ``` ### Response #### Success Response (200) - **Allow** (string) - A comma-separated list of allowed HTTP methods (e.g., GET). #### Response Example ```HTTP HTTP/1.1 200 OK Allow: GET ``` ``` -------------------------------- ### Install Laminas API Tools using Composer create-project Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/installation.md Installs the Laminas API Tools skeleton project using Composer's create-project command. This is a straightforward method to set up the project in a specified directory. ```console composer create-project laminas-api-tools/api-tools-skeleton path/to/install ``` -------------------------------- ### Run Laminas API Tools with built-in PHP web server Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/installation.md Starts the built-in PHP web server for the Laminas API Tools project. It binds to all interfaces on port 8080, disables error display, sets the document root to the 'public' directory, and specifies the entry point script. ```console cd path/to/install php -S 0.0.0.0:8080 -ddisplay_errors=0 -t public public/index.php ``` -------------------------------- ### Install Laminas API Tools Welcome via Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-welcome.md Installs the Laminas API Tools Welcome module using the Composer package manager. This command fetches and installs the specified package and its dependencies. ```console $ composer require laminas-api-tools/api-tools-welcome ``` -------------------------------- ### Install statuslib-example Module Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/first-rest-service.md Installs the laminas-api-tools/statuslib-example module using Composer. This is a prerequisite for the tutorial. ```console composer require laminas-api-tools/statuslib-example ``` -------------------------------- ### System Configuration Example Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-mvc-auth.md Provides an example of the `service_manager` configuration required to enable Laminas API Tools modules. ```APIDOC ## System Configuration Example ### Description This example shows the necessary `service_manager` configuration within `config/module.config.php` to enable the core functionalities of Laminas API Tools, including authentication and authorization services. ### Method N/A (Configuration setting) ### Endpoint N/A (Configuration file, typically `config/module.config.php`) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php 'service_manager' => [ 'aliases' => [ 'authentication' => 'Laminas\ApiTools\MvcAuth\Authentication', 'authorization' => 'Laminas\ApiTools\MvcAuth\Authorization\AuthorizationInterface', 'Laminas\ApiTools\MvcAuth\Authorization\AuthorizationInterface' => 'Laminas\ApiTools\MvcAuth\Authorization\AclAuthorization' ], 'factories' => [ 'Laminas\ApiTools\MvcAuth\Authentication' => 'Laminas\ApiTools\MvcAuth\Factory\AuthenticationServiceFactory', 'Laminas\ApiTools\MvcAuth\ApacheResolver' => 'Laminas\ApiTools\MvcAuth\Factory\ApacheResolverFactory', 'Laminas\ApiTools\MvcAuth\FileResolver' => 'Laminas\ApiTools\MvcAuth\Factory\FileResolverFactory', 'Laminas\ApiTools\MvcAuth\Authentication\DefaultAuthenticationListener' => 'Laminas\ApiTools\MvcAuth\Factory\DefaultAuthenticationListenerFactory', 'Laminas\ApiTools\MvcAuth\Authentication\AuthHttpAdapter' => 'Laminas\ApiTools\MvcAuth\Factory\DefaultAuthHttpAdapterFactory', 'Laminas\ApiTools\MvcAuth\Authorization\AclAuthorization' => 'Laminas\ApiTools\MvcAuth\Factory\AclAuthorizationFactory', 'Laminas\ApiTools\MvcAuth\Authorization\DefaultAuthorizationListener' => 'Laminas\ApiTools\MvcAuth\Factory\DefaultAuthorizationListenerFactory', 'Laminas\ApiTools\MvcAuth\Authorization\DefaultResourceResolverListener' => 'Laminas\ApiTools\MvcAuth\Factory\DefaultResourceResolverListenerFactory' ], 'invokables' => [ 'Laminas\ApiTools\MvcAuth\Authentication\DefaultAuthenticationPostListener' => 'Laminas\ApiTools\MvcAuth\Authentication\DefaultAuthenticationPostListener', 'Laminas\ApiTools\MvcAuth\Authorization\DefaultAuthorizationPostListener' => 'Laminas\ApiTools\MvcAuth\Authorization\DefaultAuthorizationPostListener' ] ] ``` ### Response #### Success Response (200) N/A (This is a configuration structure) #### Response Example N/A ``` -------------------------------- ### Install Swagger Adapter with Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/api-doc/swagger.md Installs the Swagger adapter dependency for API Tools documentation using Composer. This is the primary step to enable Swagger support. ```bash composer require laminas-api-tools/api-tools-documentation-swagger ``` -------------------------------- ### GET /ping Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md This endpoint is used to check the status of the API. It expects an 'Accept: application/json' header and returns a JSON response with an 'ack' field. ```APIDOC ## GET /ping ### Description Checks the status of the API. Requires an `Accept: application/json` header. ### Method GET ### Endpoint /ping ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```HTTP GET /ping HTTP/1.1 Accept: application/json ``` ### Response #### Success Response (200) - **ack** (integer) - A timestamp indicating acknowledgment. #### Response Example ```json { "ack": 1396560875 } ``` ``` -------------------------------- ### Install API Blueprint Provider using Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-documentation-apiblueprint.md Installs the laminas-api-tools/api-tools-documentation-apiblueprint package using Composer. ```console composer require laminas-api-tools/api-tools-documentation-apiblueprint ``` -------------------------------- ### Install laminas-api-tools/api-tools-mvc-auth using Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-mvc-auth.md Installs the laminas-api-tools/api-tools-mvc-auth module using the Composer package manager. ```console composer require "laminas-api-tools/api-tools-mvc-auth" ``` -------------------------------- ### Install API Tools Dependencies Source: https://github.com/laminas-api-tools/documentation/blob/master/recipes/api-tools-in-an-existing-laminas-mvc-application.md Installs the core API Tools package and development tools using Composer. ```bash $ composer require "laminas-api-tools/api-tools:~1.0" $ composer require --dev "laminas-api-tools/api-tools-admin:~1.0" $ composer require --dev "laminas/laminas-development-mode:~2.0" ``` -------------------------------- ### Install api-tools-content-negotiation via Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-content-negotiation.md This snippet shows the composer command to install the api-tools-content-negotiation module. ```console $ composer require laminas-api-tools/api-tools-content-negotiation ``` -------------------------------- ### Install MongoDB Compatibility Package Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-oauth2.md Installs the necessary compatibility package if you are using the ext/mongodb extension with the api-tools-oauth2 module. ```bash $ composer require alcaeus/mongo-php-adapter ``` -------------------------------- ### OPTIONS Request Example Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/http-negotiation.md An example of an OPTIONS request to an API endpoint. ```APIDOC ## OPTIONS /api/user ### Description This endpoint allows clients to discover which HTTP methods are supported for the `/api/user` resource. ### Method OPTIONS ### Endpoint /api/user ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```HTTP OPTIONS /api/user HTTP/1.1 Host: example.org ``` ### Response #### Success Response (200) - **Allow** (string) - A comma-separated list of allowed HTTP methods. #### Response Example ```HTTP HTTP/1.1 200 OK Allow: GET, POST ``` ``` -------------------------------- ### Install api-tools-asset-manager (Bash) Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-asset-manager.md This bash command installs the api-tools-asset-manager package as a development dependency using Composer. ```bash $ composer require --dev laminas-api-tools/api-tools-asset-manager ``` -------------------------------- ### Install API-Problem Module using Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-api-problem.md Installs the api-tools-api-problem module using the composer dependency manager. This command fetches and installs the specified package and its dependencies. ```console $ composer require laminas-api-tools/api-tools-api-problem ``` -------------------------------- ### Requesting API Documentation in Different Formats (HTTP) Source: https://github.com/laminas-api-tools/documentation/blob/master/api-doc/customize.md These HTTP examples illustrate how to request API documentation in various formats by setting the `Accept` header in your GET request. Supported formats include JSON, Swagger (JSON), and HTML. ```http GET /api-tools/documentation[/api[/service]] HTTP/1.1 Accept: application/json ``` ```http GET /api-tools/documentation[/api[/service]] HTTP/1.1 Accept: application/vnd.swagger+json ``` ```http GET /api-tools/documentation[/api[/service]] HTTP/1.1 Accept: text/html ``` -------------------------------- ### Testing OAuth2 Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-oauth2.md Instructions on how to set up and test the OAuth2 module, including database setup, password encryption, and client registration. ```APIDOC ## How to test OAuth2 To test the OAuth2 module, you need to add a `client_id` and `client_secret` to your OAuth2 database. If you are using the provided SQLite test database, a default `client_id` ('testclient') is available, and you only need to manage the `client_secret`. Passwords must be encrypted using the `bcrypt` algorithm via the `Laminas\Crypt\Password\Bcrypt` class. A helper script `bin/bcrypt.php` is included to generate password hashes from the command line: ```bash php bin/bcrypt.php ``` For example: ```bash php bin/bcrypt.php testpass ``` This will output a 60-byte hash, like: ``` $2y$14$f3qml4G2hG6sxM26VMq.geDYbsS089IBtVJ7DlD05BoViS9PFykE2 ``` Use this hash as the `client_secret` when inserting a new client into the `oauth_clients` table: ```sql INSERT INTO oauth_clients ( client_id, client_secret, redirect_uri) VALUES ( "testclient", "$2y$14$f3qml4G2hG6sxM26VMq.geDYbsS089IBtVJ7DlD05BoViS9PFykE2", "/oauth/receivecode"); ``` ``` -------------------------------- ### Install Laminas HAL via Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-hal.md Installs the Laminas HAL module using Composer, a dependency manager for PHP. This command downloads and installs the package and its dependencies. ```console $ composer require laminas-api-tools/api-tools-hal ``` -------------------------------- ### User Configuration Example Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-rest.md Example configuration for a REST contact resource within the Laminas API Tools framework. ```APIDOC ## User Configuration Example This configuration outlines a REST resource for contacts, specifying the listener, routing, HTTP methods, and entity/collection classes. ### Controller Configuration - **Controller Service Name**: `AddressBook\V1\Rest\Contact\Controller` - **Listener**: `AddressBook\V1\Rest\Contact\ContactResource` - **Route Name**: `address-book.rest.contact` - **Route Identifier Name**: `contact_id` - **Collection Name**: `contact` ### HTTP Methods #### Entity Methods - **Supported**: `GET`, `PATCH`, `PUT`, `DELETE` #### Collection Methods - **Supported**: `GET`, `POST` ### Other Configurations - **Collection Query Whitelist**: `[]` - **Page Size**: `25` - **Page Size Parameter**: `null` - **Entity Class**: `AddressBook\V1\Rest\Contact\ContactEntity` - **Collection Class**: `AddressBook\V1\Rest\Contact\ContactCollection` - **Service Name**: `Contact` ``` -------------------------------- ### Install Laminas RPC via Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-rpc.md Installs the Laminas RPC module using the Composer package manager. ```console $ composer require laminas-api-tools/api-tools-rpc ``` -------------------------------- ### HTTP OPTIONS Request Example Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/http-negotiation.md An example of an HTTP OPTIONS request to check allowed methods for the /api/user URI. ```HTTP OPTIONS /api/user HTTP/1.1 Host: example.org ``` -------------------------------- ### Install Laminas API Tools REST with Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-rest.md Command to install the laminas-api-tools/api-tools-rest package using Composer. ```console $ composer require laminas-api-tools/api-tools-rest ``` -------------------------------- ### Install laminas-api-tools/api-tools-doctrine-querybuilder Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-doctrine-querybuilder.md This command installs the Doctrine QueryBuilder module using Composer. Ensure Composer is installed and accessible in your environment. ```bash $ composer require laminas-api-tools/api-tools-doctrine-querybuilder ``` -------------------------------- ### Install api-tools-versioning with Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-versioning.md Installs the api-tools-versioning module using the Composer package manager. ```console $ composer require laminas-api-tools/api-tools-versioning ``` -------------------------------- ### Install Laminas API Tools using Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools.md This command installs the laminas-api-tools/api-tools package using Composer, enabling the use of its features for building web APIs. ```console $ composer require laminas-api-tools/api-tools ``` -------------------------------- ### Install Production Dependencies with Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/deployment/intro.md Installs Composer dependencies for the application, omitting development packages (`--no-dev`), preferring distributed packages (`--prefer-dist`) for smaller size, and optimizing the autoloader for production environments. Requires composer.phar. ```console php composer.phar install --no-dev --prefer-dist --optimize-autoloader ``` -------------------------------- ### Install HybridAuth (Bash) Source: https://github.com/laminas-api-tools/documentation/blob/master/recipes/integrate-social-logins.md Installs the HybridAuth library version dev-3.0.0-Remake using Composer. ```bash $ composer require hybridauth/hybridauth:dev-3.0.0-Remake ``` -------------------------------- ### Custom Header Versioning Examples Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/versioning.md Shows examples of using custom HTTP headers to convey API version information. ```HTTP Header X-API-Version: 2 ``` ```HTTP Header GData-Version: 2.0 ``` ```HTTP Header X-MS-Version: 2011-08-18 ``` -------------------------------- ### Install laminas-api-tools/api-tools-configuration via Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-configuration.md This snippet shows the command to install the api-tools-configuration module using Composer. It's the recommended way to add the module to your project. ```console $ composer require laminas-api-tools/api-tools-configuration ``` -------------------------------- ### HTTP OPTIONS Response Example (Success) Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/http-negotiation.md An example of a successful HTTP OPTIONS response indicating allowed methods for a URI. ```HTTP HTTP/1.1 200 OK Allow: GET, POST ``` -------------------------------- ### Install Laminas API Tools Documentation via Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-documentation.md Installs the Laminas API Tools Documentation module using the Composer package manager. This is the recommended way to add the module to your project. ```console composer require laminas-api-tools/api-tools-documentation ``` -------------------------------- ### Install zf-console via Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md Installs the zf-console library using the Composer package manager. This is the recommended way to add the library to your project dependencies. ```console composer require zfcampus/zf-console ``` -------------------------------- ### Install Laminas API Tools Provider via Composer (Console) Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-provider.md Provides the Composer command to install the laminas-api-tools/api-tools-provider package. This is the recommended method for adding the provider to a project. ```bash $ composer require laminas-api-tools/api-tools-provider ``` -------------------------------- ### HTTP Response for Unacceptable Content Type Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md This example illustrates an HTTP response from the server indicating a '406 Not Acceptable' error. It occurs when the requested 'Accept' type (text/html in this case) cannot be honored by the service. The response includes a JSON body detailing the error. ```http HTTP/1.1 406 Not Acceptable Content-Type: application/problem+json { "detail": "Cannot honor Accept type specified", "status": 406 ``` -------------------------------- ### Create and Run Console Application Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md Illustrates the complete process of setting up and running a console application. This includes setting up the dispatcher, mapping commands, configuring routes, instantiating the application, and executing it. ```php use My\SelfUpdate; use Zend\Console\Console; use ZF\Console\Application; use ZF\Console\Dispatcher; require_once __DIR__ . '/vendor/autoload.php'; // Composer autoloader define('VERSION', '1.1.3'); $dispatcher = new Dispatcher(); $dispatcher->map('self-update', new SelfUpdate($version)); $dispatcher->map('build', 'My\Build'); $application = new Application( 'Builder', VERSION, include __DIR__ . '/config/routes.php', Console::getInstance(), $dispatcher ); $exit = $application->run(); exit($exit); ``` -------------------------------- ### Install Laminas Content Validation via Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-content-validation.md Instructions on how to install the Laminas Content Validation module using the Composer package manager. ```console $ composer require laminas-api-tools/api-tools-content-validation ``` -------------------------------- ### Public .gitignore Example (Text) Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-asset-manager.md This text snippet shows an example of a .gitignore file that might be generated in the public directory by api-tools-asset-manager, listing the copied asset directories to prevent them from being committed to version control. ```text # public/.gitignore api-tools/ api-tools-welcome/ ``` -------------------------------- ### HTTP Basic Credentials Setup Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/first-rest-service.md Instructions for setting up HTTP basic authentication using an htpasswd file. ```APIDOC ## HTTP Basic Credentials Setup 1. **Generate `htpasswd` file**: Use Apache's `htpasswd` tool or an online generator. 2. **Store `htpasswd`**: Place the generated file at `data/htpasswd` in your application. 3. **Note Credentials**: Keep a record of the username and password used for future reference. ``` -------------------------------- ### Configure Validation for GET Requests Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-content-validation.md Example of mapping the 'GET' HTTP method to an input filter for validating query parameters, available since version 1.3.0. ```php 'api-tools-content-validation' => [ 'Application\Controller\HelloWorld' => [ 'GET' => 'Application\Controller\HelloWorld\QueryParamValidator', ], ], ``` -------------------------------- ### Example Method-Specific Input Filters Configuration (PHP) Source: https://github.com/laminas-api-tools/documentation/blob/master/content-validation/advanced.md Provides a practical example of configuring method-specific input filters for a controller. It shows how to set a general input filter and a specific one for POST requests. ```php [ 'api-tools-content-validation' => [ 'AddressBook\V1\Rest\Contact\Controller' => [ 'input_filter' => 'AddressBook\V1\Rest\Contact\Validator', 'POST' => 'AddressBook\V1\Rest\Contact\NewContactValidator', ], ], ] ``` -------------------------------- ### HTTP GET Request to Fetch Status Collection Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/first-rest-service.md An example HTTP GET request to the /status endpoint to retrieve a collection of status items. It specifies the Accept header for JSON response. ```http GET /status HTTP/1.1 Accept: application/json ``` -------------------------------- ### Show Installed Composer Packages (Bash) Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/updating-to-1-4.md Lists all installed Composer packages, optionally filtering for those with names starting with 'laminas-'. This is used to compare project dependencies against identified 'use Laminas\' statements. ```bash composer show ``` ```bash composer show | grep "laminas-" ``` -------------------------------- ### Example GET Request Parameters for Filtering and Sorting Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-doctrine-querybuilder.md This example demonstrates how to structure the `$_GET` superglobal array to pass filtering and sorting instructions to the Doctrine QueryBuilder. It includes an 'equals' filter on the 'name' field and a 'desc' order-by on the 'startAt' field. ```php $_GET = [ 'filter' => [ [ 'type' => 'eq', 'field' => 'name', 'value' => 'Tom', ], ], 'order-by' => [ [ 'type' => 'field', 'field' => 'startAt', 'direction' => 'desc', ], ], ]; ``` -------------------------------- ### Console Usage Reporting Example Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md Demonstrates how to observe usage reporting by executing an application with no arguments or with the 'help' argument. Shows available commands. ```console $ ./script.php Builder, version 1.1.3 Available commands: autocomplete Command autocompletion setup build Build a package help Get help for individual commands self-update Perform a self-update of the script version Display the version of the script ``` -------------------------------- ### RPC Service HTTP Method Configuration Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/http-negotiation.md Example configuration for an RPC service allowing only the GET method. ```APIDOC ## RPC Service Configuration Example ### Description Illustrates the configuration for an RPC service where only the `GET` HTTP method is permitted. ### Method GET ### Endpoint /api/your-rpc-service ### Parameters None ### Request Example ``` // Configuration visual representation, not a direct request // [RPC HTTP Methods configuration showing GET only] ``` ### Response #### Success Response (200) - **Details**: Response specific to the RPC method. #### Response Example ```json { "message": "RPC service response" } ``` ``` -------------------------------- ### REST Service HTTP Method Configuration Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/http-negotiation.md Example configuration for a REST service allowing GET/POST for collections and GET for entities. ```APIDOC ## REST Service Configuration Example ### Description Demonstrates the configuration for a REST service, allowing `GET` and `POST` for collection URIs and `GET` for entity URIs. ### Method (Collection) GET, POST ### Endpoint (Collection) /api/your-rest-service ### Method (Entity) GET ### Endpoint (Entity) /api/your-rest-service/{id} ### Parameters #### Path Parameters (Entity) - **id** (string) - Required - Identifier for the entity. ### Request Example (Collection) ```HTTP GET /api/your-rest-service HTTP/1.1 Host: example.org ``` ### Request Example (Entity) ```HTTP GET /api/your-rest-service/123 HTTP/1.1 Host: example.org ``` ### Response (Collection) #### Success Response (200 or 201) - **Data**: List of entities or created entity. ### Response Example (Collection) ```json [ { "id": 1, "name": "Item 1" }, { "id": 2, "name": "Item 2" } ] ``` ### Response (Entity) #### Success Response (200) - **Data**: Details of the requested entity. ### Response Example (Entity) ```json { "id": 123, "name": "Specific Item" } ``` ``` -------------------------------- ### Enable development mode for Laminas API Tools Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/installation.md Enables development mode for the Laminas API Tools skeleton project by executing the 'composer development-enable' command within the project's root directory. ```console cd path/to/install composer development-enable ``` -------------------------------- ### Custom API Problem with Authentication URI Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/error-reporting.md An example of a custom API Problem payload that includes an additional field 'authentication_uri' to guide the client on where to authenticate. ```JSON { "type": "/api-tools/documentation/Status-v2#oauth", "detail": "Service requires authenticated user", "status": 401, "title": "Unauthorized", "authentication_uri": "/oauth" } ``` -------------------------------- ### URL Versioning Examples Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/versioning.md Illustrates how different services use URL prefixes or query parameters to indicate API versions for easier identification. ```URL http://api.twitter.com/1.1/ ``` ```URL http://ws.audioscrobbler.com/2.0/ ``` ```URL http://openapi.etsy.com/v2 ``` ```URL ?v=1.5 ``` ```URL ?VERSION=2011-10-01 ``` -------------------------------- ### Package Application for Deployment Source: https://github.com/laminas-api-tools/documentation/blob/master/deployment/intro.md Creates a ZIP archive of the entire application contents, suitable for deployment. This command should be executed from within the application's package folder. ```console zip -r /path/to/package.zip * ``` -------------------------------- ### Unsuccessful HTTP Basic Authentication Request Source: https://github.com/laminas-api-tools/documentation/blob/master/auth/authentication-http-basic.md An example of an unsuccessful HTTP GET request due to invalid credentials. The `Authorization` header is present but contains an invalid token. ```http GET /foo HTTP/1.1 Accept: application/json Authorization: Basic #invalid-token# ``` -------------------------------- ### POST /ping Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md This endpoint allows sending a timestamp via a POST request. It expects 'Accept: application/json' and 'Content-Type: application/json' headers. However, POST is not allowed for the /ping endpoint. ```APIDOC ## POST /ping ### Description Attempts to send a timestamp via POST to the /ping endpoint. This method is not allowed. ### Method POST ### Endpoint /ping ### Parameters #### Query Parameters None #### Request Body - **timestamp** (integer) - The timestamp to send. ### Request Example ```HTTP POST /ping HTTP/1.1 Accept: application/json Content-Type: application/json { "timestamp": 1396560875 } ``` ### Response #### Error Response (405 Method Not Allowed) - **Allow** (string) - Indicates which HTTP methods are allowed (e.g., GET). #### Response Example ```HTTP HTTP/1.1 405 Method Not Allowed Allow: GET ``` ``` -------------------------------- ### Successful HTTP Basic Authentication Request Source: https://github.com/laminas-api-tools/documentation/blob/master/auth/authentication-http-basic.md An example of a successful HTTP GET request using Basic Authentication. The `Authorization` header contains the Base64 encoded username and password. ```http GET /foo HTTP/1.1 Accept: application/json Authorization: Basic cmFscGg6cmFscGg= ``` -------------------------------- ### Initializing Application with Custom Dispatcher Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md Demonstrates how to instantiate and pass a custom Dispatcher implementation to the Application constructor. ```php $application = new Application('App', 1.0, $routes, null, $dispatcher); ``` -------------------------------- ### Method Not Allowed Response Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md Shows an HTTP 405 Method Not Allowed response, indicating that the requested HTTP method is not supported for the /ping endpoint, and includes the Allow header specifying supported methods. ```HTTP HTTP/1.1 405 Method Not Allowed Allow: GET ``` -------------------------------- ### Request Authorization Token (HTTP) Source: https://github.com/laminas-api-tools/documentation/blob/master/auth/authentication-oauth2.md This snippet shows an example HTTP GET request to the OAuth2 authorization endpoint to request an access token. It includes parameters like response_type, client_id, and redirect_uri. Ensure to replace placeholders with your specific API Tools URL and configuration. ```HTTP http:///oauth/authorize?response_type=token&client_id=testclient&redirect_uri=/oauth/receivecode&state=xyz ``` -------------------------------- ### Configure REST Controller for Contact Resource Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-rest.md Example configuration for a REST controller in Laminas API Tools, specifying the resource listener, route name, and supported HTTP methods for entity and collection operations. This setup allows for defining the behavior of a 'Contact' resource within the API. ```php 'AddressBook\V1\Rest\Contact\Controller' => [ 'listener' => 'AddressBook\V1\Rest\Contact\ContactResource', 'route_name' => 'address-book.rest.contact', 'route_identifier_name' => 'contact_id', 'collection_name' => 'contact', 'entity_http_methods' => [ 0 => 'GET', 1 => 'PATCH', 2 => 'PUT', 3 => 'DELETE', ], 'collection_http_methods' => [ 0 => 'GET', 1 => 'POST', ], 'collection_query_whitelist' => [], 'page_size' => 25, 'page_size_param' => null, 'entity_class' => 'AddressBook\V1\Rest\Contact\ContactEntity', 'collection_class' => 'AddressBook\V1\Rest\Contact\ContactCollection', 'service_name' => 'Contact', ], ``` -------------------------------- ### Implement RPC Service Controller in PHP Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/getting-started.md This PHP code defines a controller for an RPC service. It imports the ViewModel class and returns a ViewModel object containing the current timestamp in the 'ack' field when the 'pingAction' is executed. This is a core part of handling requests and preparing responses in Laminas API Tools. ```php namespace Status\V1\Rpc\Ping; use Laminas\Mvc\Controller\AbstractActionController; use Laminas\ApiTools\ContentNegotiation\ViewModel; class PingController extends AbstractActionController { public function pingAction() { return new ViewModel([ 'ack' => time() ]); } } ``` -------------------------------- ### zfdeploy Build Command Syntax and Options Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-deploy.md Details the full syntax of the 'build' command, including all available arguments and options. This is crucial for customizing the package creation process. ```bash Usage: build [--target=] [--modules=] [--vendor|-v]:vendor [--composer=] [--gitignore=] [--deploymentxml=] [--zpkdata=] [--version=] Arguments: Name of the package file to create; suffix must be .zip, .tar, .tar.gz, .tgz, or .zpk --target The target directory of the application to package; defaults to current working directory --modules Comma-separated list of modules to include in build --vendor|-v Whether or not to include the vendor directory (disabled by default) --composer Whether or not to execute composer; "on" or "off" ("on" by default) --gitignore Whether or not to parse the .gitignore file to determine what files/folders to exclude; "on" or "off" ("on" by default) --configs Path to directory containing application config files to include in the package --deploymentxmlPath to a custom deployment.xml to use when building a ZPK package --zpkdata Path to a directory containing ZPK package assets (deployment.xml, logo, scripts, etc.) --version Specific application version to use for a ZPK package ``` -------------------------------- ### Deploy Application with zs-client Source: https://github.com/laminas-api-tools/documentation/blob/master/deployment/intro.md Deploys a new application package to Zend Server. Requires the application package filename, the base URL for the application, and the SDK target name. Optional flags include creating a new vhost, using the default server, and providing a human-readable application name. ```console $ zs-client.phar applicationDeploy --appPackage= --baseUrl= --target ``` -------------------------------- ### Creating Console Routes Programmatically Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md Demonstrates how to create a ZF\Console\Route instance with various parameters like name, route, constraints, defaults, aliases, filters, and validators. It also shows methods for setting descriptions and options. ```php $route = new ZF\Console\Route( $name, $route, $constraints, // optional $defaults, // optional $aliases, // optional $filters, // optional $validators // optional ); $route->setDescription($description); $route->setShortDescription($shortDescription); $route->setOptionsDescription($optionsDescription); ``` -------------------------------- ### Reset dependencies for PHP 7.1+ with Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/intro/installation.md Prepares the Laminas API Tools skeleton for PHP 7.1+ by removing the composer.lock file and the vendor directory, then reinstalling dependencies with Composer. This ensures the latest compatible versions are used. ```console rm composer.lock && rm -rf vendor composer install ``` -------------------------------- ### Install api-tools-doctrine Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-doctrine.md Installs the laminas-api-tools/api-tools-doctrine package using Composer. ```console $ composer require laminas-api-tools/api-tools-doctrine ``` -------------------------------- ### Console Version Reporting Example Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md Shows how to observe version reporting by executing 'script --version' or 'script -v'. Displays the application's version information. ```console $ ./script --version Builder, version 1.1.3 ``` -------------------------------- ### Create SDK Target with zs-client Source: https://github.com/laminas-api-tools/documentation/blob/master/deployment/intro.md Creates a new target configuration for the SDK client. This involves specifying a target name, Zend Server key, and optionally the Zend Server URL and HTTP options for SSL verification. ```console $ zs-client.phar addTarget --target= --zskey= --zssecret= ``` ```console $ zs-client.phar addTarget --target=api --zskey=api --zssecret= --zsurl="https://foobar.tld:100082" --http="sslverify=0&sslverifypeer=0" ``` -------------------------------- ### zfdeploy Available Commands Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-deploy.md Lists the primary commands available in the zfdeploy tool, including 'build', 'help', 'self-update', and 'version'. This provides an overview of the tool's capabilities. ```bash zfdeploy ZFDeploy, version 0.3.0-dev Available commands: build Build a deployment package help Get help for individual commands self-update Updates zfdeploy.phar to the latest version version Display the version of the script ``` -------------------------------- ### XML-RPC Fault Response Example Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/what-is-an-api.md An example of an XML-RPC fault response, indicating an error occurred due to insufficient parameters. ```HTTP HTTP/1.1 200 OK Content-Type: text/xml faultCode 422 faultString Too few parameters passed; must include message, user, and timestamp timestamp> 20140328T15:22:21 ``` -------------------------------- ### Composer Configuration for Console Scripts (JSON) Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md This JSON configuration shows how to set up Composer to install a console script. By including the script in the 'bin' key, it becomes available in the vendor/bin directory, making it easily accessible for users of the application. ```json { "require": { "php": ">=5.3.23", "zfcampus/zf-console": ">=1.0" }, "bin": ["script.php"] } ``` -------------------------------- ### Install api-tools-oauth2 with Composer Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/api-tools-oauth2.md Installs the api-tools-oauth2 module using Composer. This is the primary method for adding the module to a Laminas project. ```bash $ composer require laminas-api-tools/api-tools-oauth2 ``` -------------------------------- ### POST Request to Create User Resource (HTTP) Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/halprimer.md Example of a POST request to create a new user resource. It includes the Accept and Content-Type headers, and the request body containing user details. The API is expected to assign links. ```HTTP POST /api/user HTTP/1.1 Accept: application/json Content-Type: application/vnd.example.user+json { "id": "matthew", "name": "Matthew Weier O'Phinney", "contacts": [ { "id": "mac_nibblet" }, { "id": "spiffyjr" } ], "website": { "id": "mwop" } } ``` -------------------------------- ### Download ZFDeploy PHAR using wget Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-deploy.md Downloads the ZFDeploy PHAR file using the wget command-line tool. Saves the downloaded file as zfdeploy.phar. ```bash $ wget https://packages.zendframework.com/zf-deploy/zfdeploy.phar ``` -------------------------------- ### XML-RPC Success Response Example Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/what-is-an-api.md An example of a successful XML-RPC response, returning a structured value (struct) containing the result of the operation. ```HTTP HTTP/1.1 200 OK Content-Type: text/xml status First post! user mwop timestamp> 20140328T15:22:21 ``` -------------------------------- ### Media Type Versioning Examples Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/versioning.md Demonstrates two approaches to embedding version information within the Accept header for media type versioning. ```HTTP Header Accept: application/vnd.status.v2+json ``` ```HTTP Header Accept: application/vnd.status+json; version=2 ``` -------------------------------- ### Bootstrap ZF2 Application for Console Scripts (PHP) Source: https://github.com/laminas-api-tools/documentation/blob/master/modules/zf-console.md This script demonstrates how to bootstrap a Zend Framework 2 application outside of the standard MVC lifecycle. It initializes the application, retrieves services from the ServiceManager, and sets up a console dispatcher for handling commands. Dependencies include Zend Console and ZF Console components. ```php use Zend\Console\Console; use Zend\Console\ColorInterface as Color; use ZF\Console\Application; use ZF\Console\Dispatcher; chdir(dirname(__DIR__)); require 'init_autoloader.php'; // grabs the Composer autoloader and/or ZF2 autoloader $application = Zend\Mvc\Application::init(require 'config/application.config.php'); $services = $application->getServiceManager(); $buildModel = $services->get('My\BuildModel'); $dispatcher = new Dispatcher(); $dispatcher->map('build', function ($route, $console) use ($buildModel) { $opts = $route->getMatches(); $result = $buildModel->build($opts['package'], $opts['target']); if (! $result) { $console->writeLine('Error building package!', Color::WHITE, Color::RED); return 1; } $console->writeLine('Finished building package ' . $opts['package'], Color::GREEN); return 0; }); $application = new Application( 'Builder', VERSION, array( array( 'name' => 'build', 'route' => 'build [--target=]', 'description' => 'Build a package, using as the package filename, and --target as the application directory to be packaged.', 'short_description' => 'Build a package', 'options_descriptions' => array( '' => 'Package filename to build', '--target' => 'Name of the application directory to package; defaults to current working directory', ), 'defaults' => array( 'target' => getcwd(), // default to current working directory ), ), ), Console::getInstance(), $dispatcher ); $exit = $application->run(); exit($exit); ``` -------------------------------- ### 405 Not Allowed Response Example Source: https://github.com/laminas-api-tools/documentation/blob/master/api-primer/http-negotiation.md An example of a 405 Not Allowed response when an unsupported HTTP method is used. ```APIDOC ## Unsupported Method Response Example ### Description This demonstrates the response when a client attempts to use an HTTP method not permitted for a resource. ### Method Any method other than those specified in the 'Allow' header (e.g., PUT, DELETE) ### Endpoint /api/user ### Parameters None ### Request Example ```HTTP PUT /api/user HTTP/1.1 Host: example.org ``` ### Response #### Error Response (405) - **Allow** (string) - A comma-separated list of allowed HTTP methods. #### Response Example ```HTTP HTTP/1.1 405 Not Allowed Allow: GET, POST ``` ```