Quick Start

In this Quick Start we are going to install the latest Phalcon REST Boilerplate. It contains predefined endpoints that serve as an example to get started.

Requirements

  • PHP 5.6 or newer
  • Phalcon 2.0.9 or newer
  • MySQL database (optional)

Installation

1. Create project

Let's start by creating a new project.

composer create-project redound/phalcon-rest-boilerplate

2. Update config files

First we want to rename the app/configs/default.template.php to app/configs/default.php and change the title as well as the description for your project.

Second, we want to rename app/configs/server.template.php to server.development.php and update your hostName as well as the database settings.

Read more on Config files

3. Import database schema

Now we can import the database schema that corresponds to the endpoints already configured.

Download database schema

A database schema without data is also available.

4. It's working

Now we've set up everything, when we open up the browser we should see the following

Documentation Export

Go to /documentation.html for a generated documentation of all your endpoints.

Test endpoints

We'll be using Postman to test the endpoints that already have been set up.

Install Postman

Postman is a Chrome extension for building, testing and documenting API requests and keeping them organized inside collections. We are going to take advantage of that. But first we need to have it installed.

Download Postman

Import Postman Collection

Next, go to /export/postman.json

Export postman.json After clicking on "Import" in Postman we can either import the collection we saved to disk and import it manually or choose the import from link option.

Import Postman Collection

We should see the imported Postman collection on the left

Authenticate

Choose the POST - /users/authenticate endpoint

Fill in credentials Fill in the credentials

  • Username demo
  • Password test123 (is stored as bcrypt)

Hit the Update Request button, then hit the Send button.

Now we should see the token inside our response

Authentication Response

Make requests with token

Copy the token and click on No environment -> Manage environments and fill in the token as the authToken variable. Then, select the environment we just created.

Create environment variable This authToken variable is send as Authorization header as Bearer eyJ0eXAiO...

Authorization Header

Create your own endpoints

Look at the following concepts to replace the examples for your own implementation