Download the PHP package qpi/laravel without Composer
On this page you can find all versions of the php package qpi/laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel
Qpi
Qpi is a query language for APIs and a runtime for fulfilling those queries with your existing data. Qpi provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time.
First of all, you should know that Qpi is an idea and you can implement it in your own language. This project is just a Qpi implementation for Laravel.
Usage
1) Install it:
2) Add to providers
Open your Laravel config file config/app.php
and add the following lines.
In the $providers
array add the service provider for this package.
3) Update autoload:
Configuration
First, you need to publish configuration file.
The configuration file is copied to config/qpi.php
.
Registering models
To give access to the models, you have to register your models in config/qpi.php
.
Quick Tutorial
This package will introduce two new routes to your app. /query/{query}
and /schema
.
If you want to make a query, just use the first endpoint like this:
And if you want to see the manual of your models, use the second endpoint: /schema
.
The Query Language
Now, you just need to know how to use it. As I said, it's query language and you have to need to learn it to make your queries. It's a simple language with few tips. Please follow the next steps.
So let's start. Each query must be between curly braces:
In the body of each query you have to define which model you want to fetch:
In the above query, we want to fetch the book
model. Someone may ask, what are the next curly braces? Those curly braces are just to tell Qpi which fields of that model you want to fetch.
If I want to complete my query, It will be like this:
If you don't specify any field, it will return all of available fields.
Nested queries: Imagine want to fetch the author of each book. So how can we do that?
You see that Qpi supports making queries for nested models.
Limiting results: If you want to specify how many records to fetch, you can do that like this:
I used above syntax to tell Qpi that I want to limit results to just 5 records. In other words, the parenthesis syntax is just this: (offset, limit)
.
Where statements:
You have to use brackets in order to write your where statements.
Operators:
Operator | Name | Example |
---|---|---|
= | Equal | id=5 |
> | Greater than | id>2 |
< | Less than | id<6 |
! | Not equal | id!6 |
~ | Like | name~'john%' |
| | OR | id<6|id>3 |
& | AND | id=6&id=3 |
Order by:
You can add a colon after every field witch you want to order results by it. After colon you have to tell Qpi the direction. 1
for ASC and 0
for DESC.
Query batching:
With a single request, you can fetch all of your needs. Just put your queries into curly braces.
Above, you see two different queries but you can fetch it with a single request.
Authorization
To enable authorization for models, you should add qpiAccess
method to each model. Qpi will call this method in each request that want's to have access to that model and if the model throws an error, Qpi will reject the request.
Note that Qpi will inject dependencies to this method.
Schema (Comming soon...)
Your users can make request to /schema
to see the schema of models. In order to do that, your models should have two optional static properties $qpiProps
and $qpiRelations
.