PHPackages                             platformsh/api-platform - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. platformsh/api-platform

ActiveProject

platformsh/api-platform
=======================

API-Platform v2 template for Platform.sh

02JavaScript

Since Oct 24Pushed 6mo agoCompare

[ Source](https://github.com/platformsh-templates/API-Platform-v2)[ Packagist](https://packagist.org/packages/platformsh/api-platform)[ RSS](/packages/platformsh-api-platform/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Warning

**This repository is no longer maintained by our internal teams.**
The template is provided *as is* and will not receive updates, bug fixes, or new features.
You are welcome to contribute on it or fork the repository and modify it for your own use. To deploy this template on [Upsun](https://www.upsun.com), you can use the command [upsun project:convert](https://docs.upsun.com/administration/cli/reference.html#projectconvert)on this codebase to convert the existing `.platform.app.yaml` configuration file to the [Upsun Flex format](https://docs.upsun.com/create-apps/app-reference/single-runtime-image.html).

[ ](https://platform.sh)

Deploy API Platform api and API Platform admin (ReactJS) on Platform.sh
=======================================================================

[](#deploy-api-platform-api-and-api-platform-admin-reactjs-on-platformsh)

**Contribute, request a feature, or check out our resources**

[**Join our community**](https://community.platform.sh) [**Documentation**](https://docs.platform.sh) [**Blog**](https://platform.sh/blog) [**Report a bug**](https://github.com/platformsh-templates/API-Platform-v2/issues/new?assignees=&labels=bug&template=bug_report.yml) [**Request a feature**](https://github.com/platformsh-templates/API-Platform-v2/issues/new?assignees=&labels=feature+request&template=improvements.yml)

[![Open issues](https://camo.githubusercontent.com/ba06e8367c3042ab2c83fcecc858981421b38b4761f7e3e5e8c3b83f51168aa1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f706c6174666f726d73682d74656d706c617465732f4150492d506c6174666f726d2d76322e7376673f7374796c653d666f722d7468652d6261646765266c6162656c436f6c6f723d66346632663326636f6c6f723d666664396439266c6162656c3d497373756573)](https://github.com/platformsh-templates/API-Platform-v2/issues) [![Open PRs](https://camo.githubusercontent.com/456831a1b26f3e366ee8df0d0e9d833de69290fe58548de7266c219609a43087/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f706c6174666f726d73682d74656d706c617465732f4150492d506c6174666f726d2d76322e7376673f7374796c653d666f722d7468652d6261646765266c6162656c436f6c6f723d66346632663326636f6c6f723d666664396439266c6162656c3d50756c6c2532307265717565737473)](https://github.com/platformsh-templates/API-Platform-v2/pulls)

---

**Contents**

[**About**](#about) [**Getting started**](#getting-started) [**Migrate**](#migrate) [**Learn**](#learn) [**Contribute**](#contribute)

---

About
-----

[](#about)

 We have just created a new multi-app project for you, based on [API Platform component](https://api-platform.com/docs/core/) and [API Platform Admin](https://api-platform.com/docs/admin/).
The generated code has been optimized for a typical web application hosted on [Platform.sh](https://platform.sh/).

### Features

[](#features)

- PHP 8.1
- PostgreSQL v13
- Composer-based build
- Yarn v1.22.15
- NodeJS v16
- a sample Greeting Entity

Getting started
---------------

[](#getting-started)

### Quickstart

[](#quickstart)

[Create a Platform.sh project](https://platform.sh/free-trial).

Clone the GitHub repository and push its content to your Platform.sh project:

```
git clone git@github.com:platformsh-templates/API-Platform-v2.git
cd API-Platform-v2/
git remote add platform [project-id]@git.[region].platform.sh:[project-id].git
git push platform main
```

You can now access the `admin` URL provided by Platform.sh and enjoy.

The quickest way to deploy this template on Platform.sh is by clicking the button below. This will automatically create a new project and initialize the repository for you.

> **Note:**
>
> Platform.sh templates prioritize upstream release versions over our own. Despite this, we update template dependencies on a scheduled basis independent of those upstreams.
> Because of this, template repos do not contain releases. This may change in the future, but until then the `-s dev` flag is necessary to use `composer create-project`.

#### Other deployment options

[](#other-deployment-options)

For all the other options below, clone this repository first:

```
git clone https://github.com/platformsh-templates/API-Platform-v2.git
```

If you're trying to deploy from GitHub, you can generate a copy of this repository first in your own namespace by clicking the [Use this template](https://github.com/platformsh-templates/API-Platform-v2/generate) button at the top of this page.

Then you can clone a copy of it locally with `git clone git@github.com:YOUR_NAMESPACE/API-Platform-v2.git`.

Deploy directly to Platform.sh from the command line1. Create a free trial:

    [Register for a 30 day free trial with Platform.sh](https://auth.api.platform.sh/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
2. Install the Platform.sh CLI

    #### Linux/OSX

    [](#linuxosx)

    ```
    curl -sS https://platform.sh/cli/installer | php
    ```

    #### Windows

    [](#windows)

    ```
    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php
    ```

    You can verify the installation by logging in (`platformsh login`) and listing your projects (`platform project:list`).
3. Set the project remote

    Find your `PROJECT_ID` by running the command `platform project:list`

    ```
    +---------------+------------------------------------+------------------+---------------------------------+
    | ID            | Title                              | Region           | Organization                    |
    +---------------+------------------------------------+------------------+---------------------------------+
    | PROJECT_ID    | Your Project Name                  | xx-5.platform.sh | your-username                   |
    +---------------+------------------------------------+------------------+---------------------------------+
    ```

    Then from within your local copy, run the command `platform project:set-remote PROJECT_ID`.
4. Push

    ```
    git push platform DEFAULT_BRANCH
    ```

Integrate with a GitHub repo and deploy pull requests1. Create a free trial:

    [Register for a 30 day free trial with Platform.sh](https://auth.api.platform.sh/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to whatever you have set at `https://YOUR_NAMESPACE/nextjs-drupal`.
2. Install the Platform.sh CLI

    #### Linux/OSX

    [](#linuxosx-1)

    ```
    curl -sS https://platform.sh/cli/installer | php
    ```

    #### Windows

    [](#windows-1)

    ```
    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php
    ```

    You can verify the installation by logging in (`platformsh login`) and listing your projects (`platform project:list`).
3. Setup the integration:

    Consult the [GitHub integration documentation](https://docs.platform.sh/integrations/source/github.html#setup) to finish connecting your repository to a project on Platform.sh. You will need to create an Access token on GitHub to do so.

Integrate with a GitLab repo and deploy merge requests1. Create a free trial:

    [Register for a 30 day free trial with Platform.sh](https://auth.api.platform.sh/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
2. Install the Platform.sh CLI

    #### Linux/OSX

    [](#linuxosx-2)

    ```
    curl -sS https://platform.sh/cli/installer | php
    ```

    #### Windows

    [](#windows-2)

    ```
    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php
    ```

    You can verify the installation by logging in (`platformsh login`) and listing your projects (`platform project:list`).
3. Create the repository

    Create a new repository on GitLab, set it as a new remote for your local copy, and push to the default branch.
4. Setup the integration:

    Consult the [GitLab integration documentation](https://docs.platform.sh/integrations/source/gitlab.html#setup) to finish connecting a repository to a project on Platform.sh. You will need to create an Access token on GitLab to do so.

Integrate with a Bitbucket repo and deploy pull requests1. Create a free trial:

    [Register for a 30 day free trial with Platform.sh](https://auth.api.platform.sh/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
2. Install the Platform.sh CLI

    #### Linux/OSX

    [](#linuxosx-3)

    ```
    curl -sS https://platform.sh/cli/installer | php
    ```

    #### Windows

    [](#windows-3)

    ```
    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php
    ```

    You can verify the installation by logging in (`platformsh login`) and listing your projects (`platform project:list`).
3. Create the repository

    Create a new repository on Bitbucket, set it as a new remote for your local copy, and push to the default branch.
4. Setup the integration:

    Consult the [Bitbucket integration documentation](https://docs.platform.sh/integrations/source/bitbucket.html#setup) to finish connecting a repository to a project on Platform.sh. You will need to create an Access token on Bitbucket to do so.

### Local development

[](#local-development)

This section provides instructions for running the `API Platform` template locally, connected to a local database instance.

In all cases for developing with Platform.sh, it's important to develop on an isolated environment - do not connect to data on your production environment when developing locally.

Each of the options below assume that you have already deployed this template to Platform.sh, as well as the following starting commands:

```
$ platform get PROJECT_ID

$ cd project-name

$ platform environment:branch new_branch
```

API Platform: using Symfony ServerIn general, the steps are as follows: 1. if you didn't get your Platform project yet, `git clone git@github.com:platformsh-templates/api-platform-api-admin.git api-platform`(or your own repo if you already created a fork)
2. `cd ./api-platform`
3. Start the API component with those steps:

    1. `cd ./api`
    2. Install the [Symfony CLI](https://symfony.com/download)
    3. start docker container for the database : `docker-compose up -d`
    4. `symfony composer install`
    5. check that your api/.env file contains a valid `DATABASE_URL` to let Symfony connect to your database
    6. `symfony console doctrine:schema:create --dump-sql` (change to option `--force` to run those sql requests)
    7. `symfony server:start -d`
    8. et voilà, you can go on `/api` to display your swagger interface, showing entities Offer and Product CRUD option

> **Note:**if symfony server does not start your app using default port 8000, please change `REACT_APP_PUBLIC_URL` from `./admin/.env` file accordingly

3. Start the admin component with those steps

    1. `cd ../admin` (assuming that you're in the `./api` folder)
    2. `yarn install`
    3. `yarn start`
    4. et voilà, a new browser tab would open at url [](http://localhost:3000/)

> **Note:**For many of the steps above, you may need to include the CLI flags `-p PROJECT_ID` and `-e ENVIRONMENT_ID` if you are not in the project directory or if the environment is associated with an existing pull request.

### Deploying to Platform.sh

[](#deploying-to-platformsh)

This repository has all of the code it needs in order to deploy to Platform.sh.

Deploy directly to Platform.sh from the command line1. Create a free trial:

    [Register for a 30 day free trial with Platform.sh](https://auth.api.platform.sh/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
2. Install the Platform.sh CLI

    #### Linux/OSX

    [](#linuxosx-4)

    ```
    curl -sS https://platform.sh/cli/installer | php
    ```

    #### Windows

    [](#windows-4)

    ```
    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php
    ```

    You can verify the installation by logging in (`platformsh login`) and listing your projects (`platform project:list`).
3. Set the project remote

    Find your `PROJECT_ID` by running the command `platform project:list`

    ```
    +---------------+------------------------------------+------------------+---------------------------------+
    | ID            | Title                              | Region           | Organization                    |
    +---------------+------------------------------------+------------------+---------------------------------+
    | PROJECT_ID    | Your Project Name                  | xx-5.platform.sh | your-username                   |
    +---------------+------------------------------------+------------------+---------------------------------+
    ```

    Then from within your local copy, run the command `platform project:set-remote PROJECT_ID`.
4. Push using git

    ```
    git push platform DEFAULT_BRANCH
    ```
5. or Push using platform

    ```
    platform push
    ```

Integrate with a GitHub repo and deploy pull requests1. Create a free trial:

    [Register for a 30 day free trial with Platform.sh](https://auth.api.platform.sh/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to whatever you have set at `https://YOUR_NAMESPACE/nextjs-drupal`.
2. Install the Platform.sh CLI

    #### Linux/OSX

    [](#linuxosx-5)

    ```
    curl -sS https://platform.sh/cli/installer | php
    ```

    #### Windows

    [](#windows-5)

    ```
    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php
    ```

    You can verify the installation by logging in (`platformsh login`) and listing your projects (`platform project:list`).
3. Setup the integration:

    Consult the [GitHub integration documentation](https://docs.platform.sh/integrations/source/github.html#setup) to finish connecting your repository to a project on Platform.sh. You will need to create an Access token on GitHub to do so.

Integrate with a GitLab repo and deploy merge requests1. Create a free trial:

    [Register for a 30 day free trial with Platform.sh](https://auth.api.platform.sh/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
2. Install the Platform.sh CLI

    #### Linux/OSX

    [](#linuxosx-6)

    ```
    curl -sS https://platform.sh/cli/installer | php
    ```

    #### Windows

    [](#windows-6)

    ```
    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php
    ```

    You can verify the installation by logging in (`platformsh login`) and listing your projects (`platform project:list`).
3. Create the repository

    Create a new repository on GitLab, set it as a new remote for your local copy, and push to the default branch.
4. Setup the integration:

    Consult the [GitLab integration documentation](https://docs.platform.sh/integrations/source/gitlab.html#setup) to finish connecting a repository to a project on Platform.sh. You will need to create an Access token on GitLab to do so.

Integrate with a Bitbucket repo and deploy pull requests1. Create a free trial:

    [Register for a 30 day free trial with Platform.sh](https://auth.api.platform.sh/register). When you have completed signup, select the **Create from scratch** project option. Give you project a name, and select a region where you would like it to be deployed. As for the *Production environment* option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.
2. Install the Platform.sh CLI

    #### Linux/OSX

    [](#linuxosx-7)

    ```
    curl -sS https://platform.sh/cli/installer | php
    ```

    #### Windows

    [](#windows-7)

    ```
    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php
    ```

    You can verify the installation by logging in (`platformsh login`) and listing your projects (`platform project:list`).
3. Create the repository

    Create a new repository on Bitbucket, set it as a new remote for your local copy, and push to the default branch.
4. Setup the integration:

    Consult the [Bitbucket integration documentation](https://docs.platform.sh/integrations/source/bitbucket.html#setup) to finish connecting a repository to a project on Platform.sh. You will need to create an Access token on Bitbucket to do so.

### Migrating your data

[](#migrating-your-data)

If you are moving an existing site to Platform.sh, then in addition to code you also need to migrate your data. That means your database and your files.

Importing the database
First, obtain a database dump from your current site and save your dump file as `database.sql`. Then, import the database into your Platform.sh site using the CLI:

```
platform sql -e main
