Download the PHP package baka/http without Composer
On this page you can find all versions of the php package baka/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package http
Baka Http
PhalconPHP package to create fast RESTful API's providing a simple way to create fast CRUD's
Table of Contents
- Testing
- REST CRUD
- Controller Configuration
- QueryParser
- QueryParser Extended
Testing
Routes Configuration
To avoid having to create Controller for CRUD api we provide the \Baka\Http\Rest\CrudController
Add to your routes.php
You can also pass params to the routes to disable JWT and in the future assigne a middleware
Controller configuration
Add
QueryParser
Parse GET request for a API , giving the user the correct phalcon model params to perform a search
QueryParser CustomFields (DEPRECATED)
Parse GET request for a API , given the same params as before but with cq (for custom domains) , this give out a normal SQL statement for a raw query
GET - /v1/?q=(searchField1:value1,searchField2:value2)&cq=(member_id:1)&q=(leads_status_id:1)
relationship of this model
QueryParser Extended
The extended query parser allows you to append search parameters directly via the controller without having to rewrite the function code.
Features include the ability to search within a model, within a model's custom fields and within a model's descendant relationships.
Parameters are passed in the format field
operator
value
. Valid operators are :
, >
, <
.
Multiple fields can be search by separating them with a ,
. You can search a field by several values by separating said values with |
(equivalent to SQL's OR
).
Query the Model
GET - /v1/model?q=(field1:value1,field2:value2|value3)
Query the Custom Fields
GET - /v1/model?cq=(field1>value1)
Query related Models
Querying related models demands a slightly different structure. Each related model that we want queried must be passed as they are named in the system, _
is used to separate camel cases.
GET - /v1/model?rq[model_name]=(field1<value1|value2)
Between
While between is strictly not supported at this time, you can produce the same result following this procedure:
GET - /v1/model?q=(field1>value1,field1<value2)
Like, Empty or Not
There is another nice feature that you can use to query the model.
Like
GET - /v1/model?q=(field1:%value)
GET - /v1/model?q=(field1:value%)
GET - /v1/model?q=(field1:%value%)
Empty
You can tell the query parser to make sure a field is empty. In the case of integer properties, the query parser will ask the model if the default value for a property is 0
. If it is, it will include 0
as an empty value.
GET - /v1/model?q=(field1:%%)
Not
This is the opposite of the above Empty.
GET - /v1/model?q=(field1:$$)
One for all, and all for One
You can use all the above described feature together in one query.
GET - /v1/model?q=(field1:value1|value2,field2>value3,field2<value4,field3:$$)&cq=(field4:value5)&rq[model_name]=(field5>value6)
Just remember to escape any special character you want to send through a query string to avoid unwanted results.
Usage
In order to access the extended query parser features your controller has to extend from CrudExtendedController
.
To append additional search parameters you simply do this:
This method uses the operators that are passed to the query parser via the URL query. Valid operators are (with their SQL equivalents):
API Custom Fields CRUD
The CRUD handles the default behavior:
- GET /v1/leads -> get all
- GET /v1/leads/1 -> get one
- POST /v1/leads -> create
- PUT /v1/leads/1 -> update
- DELETE /v1/leads/1 -> delete
In other to use the custom fields you need to extend you controller from CrudCustomFieldsController and define the method onConstruct()
on this method you define the model of the custom field and the model of the value of this custom fields
Thats it, your controller now manages the custom fields as if they wher properties of the main class
Normal API CRUD
Just extend your API controller from CrudController and you will have the following functions:
The CRUD handles the default behaviero:
- GET /v1/leads -> get all
- GET /v1/leads/1 -> get one
- POST /v1/leads -> create
- PUT /v1/leads/1 -> update
- DELETE /v1/leads/1 -> delete
createFields and updateFields are needed to be define in other to create the field
All versions of http with dependencies
ext-phalcon Version >=3.0.0
vlucas/phpdotenv Version ^2.0
phalcon/incubator Version >=3.0.0
baka/database Version ^0.5
baka/elasticsearch Version ^1.0
elasticsearch/elasticsearch Version ^6.1
guzzlehttp/guzzle Version ^6.3