Getting started

To quickly get started with PSX follow this guide which creates a working PSX environment. For more detailed informations please take a look at the offical documentation.

Requirements

  • PSX requires at least PHP >= 7.0 so you have to check whether you have the right version installed.

    php -v

  • PSX uses also composer as dependency managment tool. With the following command you can see whether composer is correctly installed. In case it is not installed you can use the following guide to setup composer.

    composer --version

Installation

  • Install the sample project of PSX with the following composer command. This creates the sample project and installs a stable version of PSX.

    composer create-project psx/sample .

  • Change the file configuration.php so that the following keys are set.

    'psx_url'      => 'http://127.0.0.1:8080',
    'psx_dispatch' => '',

  • Start the internal PHP web-server inside the public/ folder with the following command. Note this is only a setup for testing in production you want use a real web-server like Apache or Nginx with a vhost pointing to the public directory.

    php -S 127.0.0.1:8080 server.php

Endpoints

Now you should be able to visit the following endpoints:

  • Welcome http://127.0.0.1:8080

    The welcome API endpoint should given you a welcome message with further links to other endpoints.

  • API http://127.0.0.1:8080/population

    This is the example API of the project.

  • Documentation http://127.0.0.1:8080/documentation/

    The automatically generated documentation of the example API. Note there must be a trailing slash at the url.

Source code

In the following a few explanations about the important parts of the sample API.

  • src/Sample/Api/Population/Collection.php

    This is the class which represents the /population endpoint.

  • src/Sample/Service/Population.php

    Service class which contains the business logic of the API.

  • tests/Sample/Api/Population/CollectionTest.php

    Contains the PHPUnit test case for the /population endpoint. If you have phpunit installed you can run the tests in the root of the project with the phpunit command.