In addition to being the domain I landed this blog on, Fliglio is the name of the PHP Framework
we built and have been using at work for several years now. Recently we went through the
effort of cleaning it up to make available on github.
In this post I will attempt to show you how to use Fliglio with a Getting Started guide for RESTful microservices.
Running The App
Before we go any further, grab a copy of the demo application here.
git clone https://github.com/fliglio/rest-gs.git
This demo requires MySQL to back the todo entries (along with
apache or nginx and the appropriate version of php).
If that sounds like a pain in the ass, you can also use Docker. The demo repo comes with a
Makefile to easily run Fliglio services in a Docker container.
The application class is the application’s entry point and is responsible for managing configuration classes as well as actually dispatching a request.
The configuration class is responsible for things like specifying how to route a request and for instantiating application dependencies.
Typically, a microservice will also have one or more resources classes to organize behavior for individual urls.
Todo, A Microservice
I’m sure I could explain everything about the framework, but I’m also sure you wouldn’t care.
So let’s just jump in and look at the service.
Defining a resource
This should be pretty familiar if you’re used to REST apis. We’re defining methods
on this class to handle providing basic CRUD functionality for todos with http verbs.
By hinting the parameters to these methods with classes like PathParam, GetParam, and Entity, we can specify
what parameters we need to perform an action (and allow the framework to inject them rather than parsing
the Request directly.)
(Don’t worry too much about the method getWeatherAppropriate, this is a contrived
example to aid in showing how to test all of this.)
Those comments aren’t magical however; we still need to map this functionality to urls. We manage this in the
And there you have it! A framework for developing REST services.
That wasn’t a terribly in depth introduction to Fliglio, but I’ve gotta start somewhere, right?