Download the PHP package caendesilva/pikoserve without Composer
On this page you can find all versions of the php package caendesilva/pikoserve. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download caendesilva/pikoserve
More information about caendesilva/pikoserve
Files in caendesilva/pikoserve
Package pikoserve
Short Description A truly tiny framework for PHP microservices
License MIT
Informations about the package pikoserve
🍦 Pikoserve - A truly tiny framework for PHP microservices
About
Pico is a unit prefix often used for something extremely tiny. Which is just what Pikoserve is! While it is designed for writing microservices in PHP calling it a microframework seems excessive.
Pikoserve came to be in this tweet: https://twitter.com/StressedDev/status/1512860967000059907
At its core, Pikoserve is a starter template for creating tiny stateless API services and is essentially a wrapper for writing and reading JSON responses and sending the proper headers all within a single tiny class.
Installation
Since it is so lightweight you can get started by just downloading the Piko.php file (or copying and pasting it), then reference it in a PHP file (usually index.php). If you want you can even use the Piko.php file as your index.php code, just place your own code under the Piko class. Though I prefer to keep it separate to reduce clutter.
To get started quickly, you can use Composer or Git.
Usage
Create an index.php file containing the Main class. Require the Piko.php file, and write your code in the Main class. Then call Piko::boot() with the Main class. Piko will then send the headers and execute the handle method and return a JSON Response.
Setting up a starter project
The only file you need is the Piko.php file, but to get started quickly you can use the starter project in the repo.
You can also use Composer to create a new Piko project. It is not available as a package, since if you are writing something that will be dependent on several packages you will probably need something more sophisticated than Piko anyway.
This will set you up with the Piko.php file which contains the Piko class, and an index.php file that references it. Speaking of, let's take a look at what it looks like.
Hello World Example
This is the index.php file that is shipped with Piko but is shown here again to break down how Piko works.
This is all you need to run Piko. Seriously.
Extending Piko
Since Piko is designed to be so minimal, it's up to you to add any functionality you may need.
However, Piko makes it easy to fluently add functionality by adding a callback to the boot method.
For example, if you want to add a custom error handler or a server log, you can do so by adding a callback to the boot method.
The callback is executed after the handle method, i.e. after the headers and JSON response are sent.
I had an idea that this can be used to load callback modules to easily share these kinds of callbacks. If you have any ideas for such micro-packages, please let me know your ideas!