Friday, 30 June 2017

Laravel Global key-value store in the database

Sometimes we need to store some key value pairs in your project, but where we store the key value? Some of the options should update later in the process so it should be possible to change them as well.ex: check the status from a third party service and store the status.

Global Key Value Pair Laravel

You can use the package : 

composer require appstract/laravel-options

Then add the ServiceProvider to your config/app.php file:

'providers' => [

Alias :

Also add it as alias, so you can use the facade easily in your app.

'aliases' => [
    'Option' => Appstract\Options\OptionFacade::class,

Usage :

With the option() helper, we can get and set options :

// Get option

// Set option
option(['someKey' => 'someValue']);

If you want to check if an option exists, you can use the facade:

use Option;

$check = Option::exists('someKey');


It is also possible to set options within the console:

php artisan option:set {someKey} {someValue}

More details on installation and usage, check the GitHub repo.

Saturday, 24 June 2017

Lightweight PHP Framework for restful api

The first thing require is a lightweight PHP Framework to create a fast and reliable restful service. 
A framework in PHP language is considered as a means to enhance the productivity to deliver faster results without deviating from best standards and practices. Developing the REST APIs using the plain PHP is a very time-consuming process and requires a lot more effort. it is also prone to deviate from the standards and requires extensive testing.

Lightweight PHP Framework

Whereas, using a micro-framework makes the PHP Rest APIs development as smooth as a baby’s bottom. You get ready to use components, separation of logic, libraries, and freedom from security related issues without doing anything much around these areas.

In this article, I will share the information about Top Lightweight PHP Frameworks for REST APIs Development.  

Slim is revered as a one of the best PHP micro-framework that enables the developers to develop the complex web applications and APIs with ease. It provides complete flexibility, full control and enables a developer to create entire PHP web service in a single PHP file. Not only this, a presence of scalable and modular architecture allows the web developers to use exactly what is needed, nothing more and nothing less. It comprises many features like disable or enable the application debugging for debug API, and if true, Slim will display the accurate debugging information for exceptions and errors. Slim supports any PSR-7 HTTP message implementation so that you can easily inspect and manipulate HTTP message method, URI, headers, status, cookies, and more. By using Slim, you can easily build your application with concentric middleware. It will assist you to easily tweak the HTTP request and response objects near your Slim app. Slim also supports dependency injection, it enables you to have complete control of your external tools. Not only this, Slim provides a strikingly fast and powerful HTTP Router that effectively maps the route callbacks to targeted HTTP request methods and URIs.

Top features:
  • RESTful routing
  • Route passing
  • Named routes
  • Route redirects
  • Custom views
  • Route halting
  • Signed cookies
  • Custom 404 page
  • HTTP caching
  • Parameters and pattern matching
  • Custom 500 page

An interesting micro-framework that stands on the shoulder of Symfony, Pimple and is inspired by the philosophy behind Sinatra. It is a creation of Fabien Potencier and Igor Wieldler and is available free to use under the MIT license. Since beginning the concept was to make a design as lightweight as possible, enabling the additional functionality through base extensions. It exists in two forms, the fat version includes Symphony components, a Twig wrapper, template engine and more. The slim version contains the basic routing engine and a number of procedures of trying in the supplementary functionalities through the extensions. With the choice between slim or fat based codebase versions and the option to later expand upon offers a lot of choice for the developers. Silex slim version is predictably fast and is widely utilized by the smaller services or the services that depend on primary large amounts of data processing.

Top features:
  • Intuitive and concise API
  • One step controllers and routers mapping
  • Micro service container Pimple is used to build the Extension System
  • App testing made easy thanks to Request and Response abstraction using the Symfony HTTP Kernel
  • Ultralight, testable and fun to use
  • Easier to tie in third party libraries

Wave is one of the popular lightweight PHP microframeworks which is built on factory method design pattern and model-view-control architecture. It is built around resource management, caching and smart image and a native API architecture. Being a compact framework that does not include the optional libraries, it carries a very small footprint and is developed by keeping the optimizations and speeds in mind. The framework comes with a view controller and a special gateway for the web functionality with clean URLs incorporating an amazing front-end JavaScript controller.
Top features:
  • Secure and modern API-centric framework
  • API returns CSV, HTML, JSON, xml and other data formats
  • Licensed under GNU Lesser General Public License Version 3
  • Supports jQuery JavaScript framework
  • Debugging, backup, update and filesystem maintenance tools
  • 256bit Rijndael encrypted data transmission
  • Supports Apache and Nginx servers in Linux and Windows environments

Just like Wave, Limonade is, all about lightweight functionality and simplicity. It is an amazingly lightweight micro network for prototyping and rapid web development. It is inspired by the frameworks like Orbit in Lua, or  Sinatra or Camping in Ruby. The micro framework is relatively simple and easy to implement and use. It is the first choice for the developers who are looking for a straightforward, yet effective implementation. Unfortunately, Limonade is extremely small and cannot be expanded upon. It is self-contained has no “fat” and “slim” versions, unlike Silex. Additionally, it relies heavily on the global functions. It doesn’t contain a class instead defines the functions which can be used. With that said, Limonade offers the functions that complete a basic PHP set, while maintaining the uniformity with the native functions. It is easier to learn and offers everything which is expected from a modern framework including REST and MVC.
Top features:
  • Entirely self contained
  • Extremely lightweight
  • MInimalistic and simple
  • Easy to use and flexible

Lumen is stunningly fast micro-framework by the most successful PHP framework of all times - Laravel. It is extensively used to build Laravel based services and APIS. Microservices consists of loosely coupled components that are independently built but are used in a standalone or (conjunction) in a number of projects if required and this is where Lumen scores above all the rest. Lumen works best when it comes to developing the projects or the components that intend to use for Laravel. Since it is powered by the components of Laravel, just dropping a code into a Laravel installation will get the job done. Lumen works best (fastest of all the PHP frameworks including Silex, Phalcon, etc) when it comes to request handling. Download now to use rich features like caching, validation, routing, a powerful Laravel service container, etc with almost zero configuration. Lumen has the similar foundation as that of Laravel. But it is built for microservices and not much for the user-facing applications.
Top features:

  • Simple in its syntax
  • Easy to deploy
  • Lightening fast
  • Consist of pre-set range of appliances and extensions
  • Quicker response time
  • A non-measurable entity
  • More sleeker than Laravel

Lightweight frameworks offers the focussed approach to build the REST APIs and  are actively maintained to build and promote modern websites and web applications of varied size and complexities.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts