### Start Minikube Cluster
Source: https://api-platform.com/docs/v2.6/deployment/minikube
Starts Minikube with the registry and dashboard addons enabled. Ensure Minikube is installed first.
```bash
minikube start --addons registry --addons dashboard
```
--------------------------------
### Install Project Dependencies
Source: https://api-platform.com/docs/v2.6/client-generator/vuetify
Install essential libraries for routing, state management, internationalization, and validation. Also, install the API Platform client generator globally.
```bash
yarn add router lodash moment vue-i18n vue-router vuelidate vuex vuex-map-fields
yarn global add @api-platform/client-generator
```
--------------------------------
### Install Google Cloud SDK
Source: https://api-platform.com/docs/v2.6/deployment/kubernetes
Installs the Google Cloud SDK for interacting with Google Cloud services.
```bash
curl https://sdk.cloud.google.com | bash
```
--------------------------------
### Install Core API Platform Dependencies
Source: https://api-platform.com/docs/v2.6/core/bootstrap
Installs the necessary composer packages for a minimal API Platform setup. This includes the core library and its essential dependencies for annotations and property info.
```bash
composer require \
api-platform/core \
doctrine/annotations \
doctrine/common \
phpdocumentor/reflection-docblock \
symfony/property-info \
symfony/routing
```
--------------------------------
### GraphQL Query Examples
Source: https://api-platform.com/docs/v2.6/core/graphql
Examples of how to query the custom GraphQL operations defined for the Book resource.
```APIDOC
## GraphQL Query Examples
### Description
Illustrates how to execute the custom GraphQL queries defined in the `Book` resource configuration.
### Query Examples
```graphql
{
retrievedQueryBook(id: "/books/56") {
title
}
notRetrievedQueryBook {
title
}
withDefaultArgsNotRetrievedQueryBook(id: "/books/56") {
title
}
withCustomArgsQueryBook(id: "/books/23", log: true, logDate: "2019-12-20") {
title
}
collectionQueryBooks {
edges {
node {
title
}
}
}
}
```
```
--------------------------------
### Navigate to Project Directory
Source: https://api-platform.com/docs/v2.6
Change into the newly created project directory to begin installing dependencies.
```bash
cd bookshop-api
```
--------------------------------
### Start Integrated Web Server
Source: https://api-platform.com/docs/v2.6/client-generator/react
Launch the development server to view and test your React application.
```bash
yarn start
```
--------------------------------
### Install Alice for Testing
Source: https://api-platform.com/docs/v2.6/distribution/testing
Install the Alice package for creating data fixtures. This command is run within a Docker Compose environment.
```bash
docker-compose exec php \
composer require --dev alice
```
--------------------------------
### Troubleshoot Xdebug Installation
Source: https://api-platform.com/docs/v2.6/distribution/debugging
Verify the Xdebug installation by running `php --version` inside the Docker container. The output should display the installed Xdebug version.
```bash
$ docker-compose exec php \
php --version
PHP …
with Xdebug v3.1.3, Copyright (c) 2002-2021, by Derick Rethans
…
```
--------------------------------
### Install GraphQL Support
Source: https://api-platform.com/docs/v2.6
Install the graphql-php library and clear the cache to enable GraphQL support. This command is executed within the Docker container.
```bash
docker-compose exec php sh -c '
composer require webonyx/graphql-php
bin/console cache:clear
'
```
--------------------------------
### Install Testing Packages
Source: https://api-platform.com/docs/v2.6/core/testing
Install the necessary packages for the API Platform test client. This command should be run within the Docker container.
```bash
docker-compose exec php \
composer require symfony/browser-kit symfony/http-client
```
--------------------------------
### Install Testing Dependencies
Source: https://api-platform.com/docs/v2.6/distribution/testing
Install the Symfony test pack, Symfony HttpClient, and JSON Schema for PHP using Composer.
```bash
docker-compose exec php \
composer require --dev symfony/test-pack symfony/http-client justinrainbow/json-schema
```
--------------------------------
### Install Expo CLI and Initialize React Native App
Source: https://api-platform.com/docs/v2.6/client-generator/react-native
Install the Expo CLI globally and create a new React Native application using the blank template. Navigate into the newly created project directory.
```bash
yarn global add expo-cli
expo init my-app
cd my-app
```
--------------------------------
### Custom DNS Configuration Example
Source: https://api-platform.com/docs/v2.6/deployment/traefik
This example shows how to add custom DNS entries to your /etc/hosts file to map local hostnames to 127.0.0.1. This is useful for testing custom domain names in a local environment.
```bash
# /etc/hosts
# ...
127.0.0.1 your.domain.com
```
--------------------------------
### Optional: Install Bootstrap and Font Awesome
Source: https://api-platform.com/docs/v2.6/client-generator/react
Enhance your application's appearance by adding UI component libraries.
```bash
yarn add bootstrap font-awesome
```
--------------------------------
### Install Project Dependencies
Source: https://api-platform.com/docs/v2.6/client-generator/vuejs
Install core Vue.js libraries for routing and state management, along with Babel plugins and presets for transpilation, and lodash for utility functions.
```bash
yarn add vue-router vuex vuex-map-fields babel-plugin-transform-builtin-extend babel-preset-es2015 babel-preset-stage-2 lodash
```
--------------------------------
### Start the React Native Application
Source: https://api-platform.com/docs/v2.6/client-generator/react-native
Execute the command to start the Expo development server and run your React Native application on a simulator or device.
```bash
expo start
```
--------------------------------
### Install VichUploaderBundle
Source: https://api-platform.com/docs/v2.6/core/file-upload
Install the VichUploaderBundle using Composer. This command adds the necessary package to your project.
```bash
docker-compose exec php \
composer require vich/uploader-bundle
```
--------------------------------
### Start Nuxt.js Project
Source: https://api-platform.com/docs/v2.6/client-generator/nuxtjs
Launch your Nuxt.js development server using yarn dev and access your application at `https://localhost:3000/books/`.
```bash
yarn dev
```
--------------------------------
### Install TypeScript Dependencies
Source: https://api-platform.com/docs/v2.6/client-generator/nextjs
Enable TypeScript in your Next.js project by installing the necessary development dependencies.
```bash
yarn add --dev typescript @types/react @types/node
```
--------------------------------
### Symfony Messenger values.yaml Example
Source: https://api-platform.com/docs/v2.6/deployment/kubernetes
Example configuration for the 'command' and 'commandArgs' in your values.yaml file to run the messenger:consume command.
```yaml
command: ['bin/console']
commandArgs: ['messenger:consume', 'async', '--memory-limit=100M']
```
--------------------------------
### Install API Platform Core with Composer
Source: https://api-platform.com/docs/v2.6/core/getting-started
Use this Composer command to install the standalone API Platform bundle into an existing Symfony Flex project. No mandatory configuration is required initially.
```bash
composer require api
```
--------------------------------
### Install and Configure Blackfire Probe in Dockerfile
Source: https://api-platform.com/docs/v2.6/core/performance
Install the Blackfire probe within your application container. This involves downloading the probe, extracting it, and configuring PHP to use it.
```dockerfile
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8307\n" > $PHP_INI_DIR/conf.d/blackfire.ini
```
--------------------------------
### Create New Vue App and Install Vuetify
Source: https://api-platform.com/docs/v2.6/client-generator/vuetify
After rebuilding Docker containers, create a new Vue app, add Vuetify, and install necessary Vue packages.
```bash
docker-compose exec client \
vue create -d .
docker-compose exec client \
vue add vuetify
docker-compose exec client \
yarn add router lodash moment vue-i18n vue-router vuelidate vuex vuex-map-fields
```
--------------------------------
### GraphQL Query Examples
Source: https://api-platform.com/docs/v2.6/core/graphql
Examples of how to call the custom GraphQL queries defined in the ApiResource. Note the naming convention for collection queries (pluralized).
```graphql
{
retrievedQueryBook(id: "/books/56") {
title
}
notRetrievedQueryBook {
title
}
withDefaultArgsNotRetrievedQueryBook(id: "/books/56") {
title
}
withCustomArgsQueryBook(id: "/books/23", log: true, logDate: "2019-12-20") {
title
}
collectionQueryBooks {
edges {
node {
title
}
}
}
}
```
--------------------------------
### Install Vue CLI and Vuetify Generator with Docker
Source: https://api-platform.com/docs/v2.6/client-generator/vuetify
Add the API Platform client generator and Vue CLI to the Dockerfile. Rebuild containers to install them.
```bash
RUN yarn global add @api-platform/client-generator @vue/cli @vue/cli-service-global
```
--------------------------------
### Create New Symfony Project
Source: https://api-platform.com/docs/v2.6/distribution
Use the Symfony CLI to create a new Symfony project. This is the initial step for a local installation.
```bash
symfony new bookshop-api
```
--------------------------------
### Setup Exception Handling
Source: https://api-platform.com/docs/v2.6/core/bootstrap
Configures exception handling components, including an exception action controller and exception listeners.
```php
$controller = new ExceptionAction($serializer, $errorFormats, $exceptionToStatus);
$errorListener = new ErrorListener($controller);
$exceptionListener = new ExceptionListener($controller, null, $debug, $errorListener);
```
--------------------------------
### Install LexikJWTAuthenticationBundle
Source: https://api-platform.com/docs/v2.6/core/jwt
Use this command to add the JWT authentication bundle to your project via Composer.
```bash
docker-compose exec php \
composer require jwt-auth
```
--------------------------------
### Absolute URL Collection Output Example
Source: https://api-platform.com/docs/v2.6/core/url-generation-strategy
Shows the collection output when absolute URLs are configured for URL generation.
```json
{
"@context": "http://example.com/contexts/Book",
"@id": "http://example.com/books",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "http://example.com/books/1",
"@type": "https://schema.org/Book",
"name": "My awesome book"
}
],
"hydra:totalItems": 1
}
```
--------------------------------
### SearchFilter with Partial Strategy
Source: https://api-platform.com/docs/v2.6/core/filters
Example of configuring a SearchFilter with a 'partial' matching strategy on a property.
```php
#[ApiFilter(SearchFilter::class, strategy: 'partial')]
```
--------------------------------
### Install Required Dependencies
Source: https://api-platform.com/docs/v2.6/client-generator/react
Add essential libraries for state management, forms, and routing to your React project.
```bash
yarn add redux react-redux redux-thunk redux-form react-router-dom connected-react-router prop-types lodash
```
--------------------------------
### Explicitly Defining GET Operations with Method
Source: https://api-platform.com/docs/v2.6/core/operations
This example shows how to explicitly define the GET method for both collection and item operations, providing more control over the operation configuration.
```APIDOC
## GET Collection Operation (Explicit)
### Description
Retrieves a collection of resources with an explicitly defined GET method.
### Method
GET
### Endpoint
/books
### Request Example
(No request body for GET)
### Response
#### Success Response (200)
- `data` (array) - An array of book resources.
### Response Example
```json
{
"@context": "/api/contexts/Books",
"@id": "/books",
"@type": "/schemas/Collection",
"hydra:member": [
{
"@id": "/books/1",
"@type": "/schemas/Book",
"id": 1,
"name": "The Hitchhiker's Guide to the Galaxy"
}
],
"hydra:totalItems": 1
}
```
## GET Item Operation (Explicit)
### Description
Retrieves a specific resource by its identifier with an explicitly defined GET method.
### Method
GET
### Endpoint
/books/{id}
### Parameters
#### Path Parameters
- **id** (integer) - Required - The unique identifier of the book.
### Request Example
(No request body for GET)
### Response
#### Success Response (200)
- `id` (integer) - The unique identifier of the book.
- `name` (string) - The name of the book.
### Response Example
```json
{
"@context": "/api/contexts/Book",
"@id": "/books/1",
"@type": "/schemas/Book",
"id": 1,
"name": "The Hitchhiker's Guide to the Galaxy"
}
```
```
--------------------------------
### Set up Redux Store and App Entry Point
Source: https://api-platform.com/docs/v2.6/client-generator/react-native
Configure the main App.js file to initialize the Redux store with necessary reducers and middleware. This includes setting up global polyfills for Buffer, URL, and EventSource.
```javascript
// App.js
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import { createStore, applyMiddleware, combineReducers } from 'redux';
import { View } from 'react-native';
import {reducer as form} from 'redux-form';
// see https://github.com/facebook/react-native/issues/14796
import { Buffer } from 'buffer';
global.Buffer = Buffer;
// see https://github.com/facebook/react-native/issues/16434
import { URL, URLSearchParams } from 'whatwg-url';
global.URL = URL;
global.URLSearchParams = URLSearchParams;
// see https://github.com/facebook/react-native/issues/12890
import RNEventSource from 'react-native-event-source';
global.EventSource = RNEventSource;
// Replace "book" with the name of resource type
import book from './reducers/book';
import Router from './Router';
export default class App extends Component {
render() {
const store = createStore(combineReducers({
book,
form
}), {}, applyMiddleware(thunk));
return (
);
}
}
```
--------------------------------
### Install API Platform Admin Library
Source: https://api-platform.com/docs/v2.6/admin/getting-started
Add the API Platform Admin package to your project's dependencies using Yarn.
```bash
yarn add @api-platform/admin
```
--------------------------------
### Initialize Documentation Action
Source: https://api-platform.com/docs/v2.6/core/bootstrap
Sets up the OpenApiFactory and DocumentationAction to generate API documentation. This is typically used when the API documentation route is accessed.
```php
final class DocumentationAction
{
private $openApiFactory;
public function __construct(OpenApiFactoryInterface $openApiFactory)
{
$this->openApiFactory = $openApiFactory;
}
public function __invoke(Request $request): DocumentationInterface
{
$context = ['base_url' => $request->getBaseUrl(), 'spec_version' => 3];
if ($request->query->getBoolean('api_gateway')) {
$context['api_gateway'] = true;
}
return $this->openApiFactory->__invoke($context);
}
}
$paginationOptions = new PaginationOptions();
$openApiOptions = new OpenApiOptions('API Platform');
$jsonSchemaTypeFactory = new TypeFactory($resourceClassResolver);
$jsonSchemaFactory = new SchemaFactory($jsonSchemaTypeFactory, $resourceMetadataFactory, $propertyNameCollectionFactory, $propertyMetadataFactory, $nameConverter, $resourceClassResolver);
$openApiFactory = new OpenApiFactory($resourceNameCollectionFactory, $resourceMetadataFactory, $propertyNameCollectionFactory, $propertyMetadataFactory, $jsonSchemaFactory, $jsonSchemaTypeFactory, $operationPathResolver, $filterLocator, $subresourceOperationFactory, $identifiersExtractor, $formats, $openApiOptions, $paginationOptions);
$documentationAction = new DocumentationAction($openApiFactory);
$routes->add('api_doc', new Route('/docs.{_format}', ['_controller' => $documentationAction, '_format' => null, '_api_respond' => true]));
```
--------------------------------
### Enabling Readonly GET Operations for Collection and Item
Source: https://api-platform.com/docs/v2.6/core/operations
This example demonstrates how to enable only the built-in GET operation for both collection and item endpoints using annotations, YAML, and XML, effectively creating a read-only resource.
```APIDOC
## GET Collection Operation
### Description
Retrieves a collection of resources.
### Method
GET
### Endpoint
/books
### Request Example
(No request body for GET)
### Response
#### Success Response (200)
- `data` (array) - An array of book resources.
### Response Example
```json
{
"@context": "/api/contexts/Books",
"@id": "/books",
"@type": "/schemas/Collection",
"hydra:member": [
{
"@id": "/books/1",
"@type": "/schemas/Book",
"id": 1,
"name": "The Hitchhiker's Guide to the Galaxy"
}
],
"hydra:totalItems": 1
}
```
## GET Item Operation
### Description
Retrieves a specific resource by its identifier.
### Method
GET
### Endpoint
/books/{id}
### Parameters
#### Path Parameters
- **id** (integer) - Required - The unique identifier of the book.
### Request Example
(No request body for GET)
### Response
#### Success Response (200)
- `id` (integer) - The unique identifier of the book.
- `name` (string) - The name of the book.
### Response Example
```json
{
"@context": "/api/contexts/Book",
"@id": "/books/1",
"@type": "/schemas/Book",
"id": 1,
"name": "The Hitchhiker's Guide to the Galaxy"
}
```
```
--------------------------------
### Test HTTP Collection Response
Source: https://api-platform.com/docs/v2.6/core/testing
This example demonstrates how to make a GET request to a collection endpoint and assert the response is successful and has the correct content type.
```php
request('GET', '/books');
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
}
}
```
--------------------------------
### Generated JSON-LD for Book Resource
Source: https://api-platform.com/docs/v2.6/core/external-vocabularies
When using external IRIs, the generated JSON-LD for a resource will include the specified type and property IRIs. This example shows the output for a GET request to a book resource.
```json
{
"@context": "/contexts/Book",
"@id": "/books/22",
"@type": "https://schema.org/Book",
"name": "My awesome book"
}
```
--------------------------------
### Initialize Vue App with Store, Router, and Plugins
Source: https://api-platform.com/docs/v2.6/client-generator/vuetify
Configure the main Vue instance, integrating Vuelidate, i18n, router, store, and Vuetify for the application.
```javascript
// main.js
import Vue from 'vue';
import Vuelidate from 'vuelidate';
import App from './App.vue';
import vuetify from './plugins/vuetify';
import store from './store';
import router from './router';
import i18n from './i18n';
Vue.config.productionTip = false;
Vue.use(Vuelidate);
new Vue({
i18n,
router,
store,
vuetify,
render: h => h(App)
}).$mount('#app');
```
--------------------------------
### Decorate JSON-LD Item Normalizer to Add Extra Data
Source: https://api-platform.com/docs/v2.6/core/serialization
Decorate the default JSON-LD item normalizer to add extra information, like a timestamp, to the serialized output for GET requests. This specific example only affects JSON-LD format.
```yaml
# api/config/services.yaml
services:
'App\Serializer\ApiNormalizer':
# By default .inner is passed as argument
decorates: 'api_platform.jsonld.normalizer.item'
```
--------------------------------
### PHP: Define Serialization Groups per Operation
Source: https://api-platform.com/docs/v2.6/core/serialization
Use the `#[ApiResource]` attribute to define default normalization contexts and override them for specific item operations like 'put'. This example shows how to set different groups for GET and PUT operations on the Book entity.
```php
['get']],
itemOperations: [
'get',
'put' => [
'normalization_context' => ['groups' => ['put']],
],
],
)]
class Book
{
#[Groups(["get", "put"])]
public $name;
#[Groups("get")]
public $author;
// ...
}
```
--------------------------------
### Create Database and Schema
Source: https://api-platform.com/docs/v2.6
Set up the database and its schema using Doctrine commands provided by the Symfony CLI.
```bash
symfony console doctrine:database:create
symfony console doctrine:schema:create
```
--------------------------------
### User Entity Example
Source: https://api-platform.com/docs/v2.6/core/extensions
Example User entity definition.
```php
add('api_entrypoint', new Route('/{index}.{_format}', ['_controller' => $entryPointAction, '_format' => null, '_api_respond' => true, 'index' => 'index'], ['index' => 'index']));
```
--------------------------------
### Build Docker Images
Source: https://api-platform.com/docs/v2.6/deployment/minikube
Builds the Docker images for the API, Caddy, and PWA components, tagging them for the Minikube registry.
```bash
docker build -t localhost:5000/php api --target api_platform_php
docker build -t localhost:5000/caddy api --target api_platform_caddy
docker build -t localhost:5000/pwa pwa --target api_platform_pwa_prod
```
--------------------------------
### Install API Platform Server Component
Source: https://api-platform.com/docs/v2.6
Install the API Platform server component into your existing Symfony project using the Symfony CLI and Composer.
```bash
symfony composer require api
```
--------------------------------
### Install Generator Dependencies
Source: https://api-platform.com/docs/v2.6/client-generator/nextjs
Install the required runtime dependencies for the API Platform client generator, including lodash utilities and formik for form handling.
```bash
yarn add lodash.get lodash.has @types/lodash isomorphic-unfetch formik
```
--------------------------------
### Custom Mutation Usage Example
Source: https://api-platform.com/docs/v2.6/core/graphql
Provides examples of how to call custom mutations in a GraphQL query, including mutations with custom arguments and disabled stages.
```APIDOC
Your custom mutations will be available like this:
```graphql
{
mutation {
mutationBook(input: {id: "/books/18", title: "The Fitz and the Fool"}) {
book {
title
}
}
}
mutation {
withCustomArgsMutationBook(input: {sendMail: true, clientMutationId: "myId"}) {
book {
title
}
clientMutationId
}
}
mutation {
disabledStagesMutationBook(input: {id: "/books/18", title: "The Fitz and the Fool"}) {
book {
title
}
clientMutationId
}
}
}
```
```
--------------------------------
### Create Quasar App
Source: https://api-platform.com/docs/v2.6/client-generator/quasar
Use the quasar-cli to create a new Quasar Framework application.
```bash
quasar create my-app
cd my-app
```
--------------------------------
### GET /grimoire/{id}
Source: https://api-platform.com/docs/v2.6/core/operations
Configures a GET operation for a specific Book resource, including path parameter requirements, default values, and host configuration.
```APIDOC
## GET /grimoire/{id}
### Description
This endpoint retrieves a specific book resource by its ID. It requires the ID to be an integer and allows for custom host and scheme configurations.
### Method
GET
### Endpoint
/grimoire/{id}
### Parameters
#### Path Parameters
- **id** (integer) - Required - The unique identifier of the book.
#### Query Parameters
(None specified in source)
#### Request Body
(Not applicable for GET requests)
### Response
#### Success Response (200)
(Schema not provided in source)
### Example
#### Request Example
(No example provided in source)
#### Response Example
(No example provided in source)
```
--------------------------------
### Setup Request Context, Matcher, and Generator - PHP
Source: https://api-platform.com/docs/v2.6/core/bootstrap
This section sets up the RequestContext, UrlMatcher, and UrlGenerator, which are essential components for handling incoming requests and generating URLs within the API.
```php
$requestContext = new RequestContext();
$matcher = new UrlMatcher($routes, $requestContext);
$generator = new UrlGenerator($routes, $requestContext);
```
--------------------------------
### Start Built-in PHP Server
Source: https://api-platform.com/docs/v2.6
Launch the built-in PHP development server using the Symfony CLI to serve your API Platform application.
```bash
symfony serve
```
--------------------------------
### Enable GET Operation for Collection and Item (XML)
Source: https://api-platform.com/docs/v2.6/core/operations
Define XML to enable only the 'get' operation for both collection and item endpoints, creating a read-only resource.
```xml
```
--------------------------------
### Enable GET Operation for Collection and Item (YAML)
Source: https://api-platform.com/docs/v2.6/core/operations
Configure YAML to enable only the 'get' operation for both collection and item endpoints, resulting in a read-only resource.
```yaml
# api/config/api_platform/resources.yaml
App\Entity\Book:
collectionOperations:
get: ~ # nothing more to add if we want to keep the default controller
itemOperations:
get: ~
```
--------------------------------
### Enable GET Operation for Collection and Item (Annotation)
Source: https://api-platform.com/docs/v2.6/core/operations
Use annotations to enable only the 'get' operation for both collection and item endpoints. This creates a read-only resource.
```php
handle($request);
$response->send();
$kernel->terminate($request, $response);
```
--------------------------------
### Verify Entrypoint URL
Source: https://api-platform.com/docs/v2.6/client-generator/troubleshooting
If you encounter an error stating that 'ApiDocumentation' does not exist, you might have provided the documentation URL instead of the API entrypoint. Ensure the URL points to the API's main entrypoint.
```bash
curl https://demo.api-platform.com/
```