Download the PHP package monomelodies/monki without Composer

On this page you can find all versions of the php package monomelodies/monki. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package monki

Monki

Simple API bootstrapper.

Monki is a library that allows you to quickly add a basic API to your project. Providing an API is becoming more and more important for several reasons:

Installation

Composer (recommended)

Manual

Download or clone the repo, and add /path/to/monki/src to your PSR-4 autoloader for the Monki\\ namespace.

Setting up

Monki implements a pipeline using league/pipeline:

Your front controller (e.g. index.php) can then add it to its pipeline (see the league/pipeline docs for more information):

If you're not using a pipeline, you can also invoke the Monki object and inspect its return value:

For emitting you could use e.g. Zend\Diactoros\Response\SapiEmitter. Diactoros is a requirement of Monki, so you already have it. But you're free to use something else.

Adding states and responses

Internally Monki's pipeline utilises the Monolyth\Reroute router. Reroute lets you specify the desired handling of HTTP requests using when('url') and then('statename', callable). Additionally you can specify callables for post, put and delete and can add pipeline stages to e.g. check user access to certain functions. You can specify all of these manually since the when method on Monki returns the actual underlying router.

However, normally any well-structured API will follow a pattern more similar to this:

This is exactly the sort of "default" API behaviour Monki aims to make easy to bootstrap! It uses the crud method for this:

In the above example, we simply pass it an instance of the Crud handler interface. The return value of the crud method can again be pipelined, e.g. for access checks. The first parameter is the base path of the endpoint, the second the one for resource-specific endpoints.

If you try to access the URL /api/user/, you won't get a list of users yet but rather find the API router returns NULL. This makes sense, since our handler doesn't actually specify any handling yet! Hey, come on, Monki has some defaults but it isn't clairvoyant...

Let's first make it respond to browse-style requests:

The list of default supported handlers is as follows:

To reuse your handler for multiple tables, you could e.g. pass the table name in the constructor and store it privately.

Full example

The following is a complete, working example using Quibble\Query for database querying (see their documentation for more information on the Quibble query builder).

Obviously this is rather bare bones as it does zero error checking, but you get the idea. Using this handler class, you can quickly setup handling for a handful of database tables:

Transforming responses

Similar to passing a PDO adapter and table name in the constructor of your handler, one might also pass a transformer (or inject it via other means). Transformers are classes or callables that "massage" your raw data before dumping it into the wide open. This is something you would implement yourself; Monki doesn't want to make assumptions. But we recommend league/fractal for this; it's a very versatile transformation tool. For simpler query result transformation you could also consider quibble/transformer.

E.g., in our user example the table would likely also contain a pass column which we don't want to expose. Or we could use it to cast the user id to an actual integer instead of a string.

Adding custom methods

Let's say we also need to add endpoints to the API for counting the total number of items in a collection (e.g. for pagination). This is possible using annotations:

To define a custom method for an endpoint with a resource, simply require the associated parameters in the method and specify a custom URL:

Internally, the Crud handler's default methods are always available using the specified HTTP methods and URL. You can annotate them, too, if you for whatever reason need to override either. The @Url annotation is appended to whatever base URL you gave the Api constructor. If omitted it is that URL that will be used verbatim (e.g. to handle HEAD or OPTIONS).

Handling things like pagination etc. based on GET or POST parameters

Knock yourself out in your handlers! You could also transform your data here, e.g. json_encode certain fields before storage. Useful packages for this might be League/Fractal and Quibble/Transformer.

What's with that name, Monki?

I'm bilingual, and in Dutch "API" is pronounced like the word for "little monkey". So that's why.


All versions of monki with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
ext-json Version *
ext-pcre Version *
ext-reflection Version *
ext-spl Version *
monolyth/reroute Version ^5.0.0
league/fractal Version ^0.14.0
laminas/laminas-diactoros Version ^2.2
zeptech/annotations Version ^1.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package monomelodies/monki contains the following files

Loading the files please wait ....