Download the PHP package vikkio88/nicu without Composer
On this page you can find all versions of the php package vikkio88/nicu. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nicu
nicu
developing micro rest api in seconds, shared hosting friendly This is a simple startup project for a nicu restful api.
Create a project
Run locally
to run this app locally using the php server just type
This will use the to simulate a simple URLRewrite
To change the default port edit the config/app.json
Or pass it as a parameter to the start.php
script
Run via docker
you can edit the file docker-compose.yml
in order to change the name of the image.
The app will be reachable at the port you specified in the docker-compose.yml
file.
How To
Add a new route
Just go to config/routes.php
and add a new route following the syntax:
There are three parameter to specify per each route:
- Route The syntax for the routes is the one specified in here.
- Method This is the HTTP verb and can be any HTTP request type (options,post,get).
- Action this is the Action that will be invoked when the route is matched, as long as it extends
ApiAction
and implementsaction()
method returning anarray
it will work fine.
Add new / read Config from action
Config lib is provided by hassankhan/config, here you can find some example of config files that are supported.
Set
To add a config, add a file or a simple array key to the one specified:
to get it
Get
if Config will be injected in the constructor, you will have access to all the configs in the 'config/ folder'
Setup the Di Container
This small framework integrated PhpDi instead of Pimple, as autowiring makes everything a bit easier to read.
To link the interface to the implementation, you need to specify a provider into config/providers
.
The provider body, will work a bit like the Laravel Providers, you will need to specify, using php-di syntax the bind between interface and implementation.
The php-di injection will autowire whatever is configured in those providers, and will inject the implementation on whatever you are creating injecting it into the Action constructor.
Example
config/providers.php
SampleProvider.php
Middlewares
Slim (so PSR) Middlewares are supported by nicu. To find out more read this.
To add a new one you need to specify it into the file config/app.php
under the config key app.middlewares
:
As ↑ shows, the config can be provided in two ways, either as a Middleware class, specifying a config as value in the array (config being an array
too), or as a simple \Callable
.
DotEnv
You can specify a config as environment variable in a .env file.
those will be loaded on the index.php
on the bootstrap phase.
And you can inject it into a config like this.
For more info about this check out vlucas/phpdotenv docs.
Build
This framework allows you to create a build version of your rest api, and it will cleanup the vendor folder in order to have less file to upload.
To run the build just type
This will create a cleaned up/production ready version of the app in the subfolder ./dist/
ready to be uploaded to your Apache or Nginx server.