https://github.com/mkgor/chiven
Simple library which allows you to build RESTful API fast, easy and flexible
https://github.com/mkgor/chiven
api api-rest http php-library php72 rest-api
Last synced: about 2 months ago
JSON representation
Simple library which allows you to build RESTful API fast, easy and flexible
- Host: GitHub
- URL: https://github.com/mkgor/chiven
- Owner: mkgor
- License: mit
- Created: 2019-10-28T11:50:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-29T08:28:19.000Z (over 6 years ago)
- Last Synced: 2025-10-17T13:19:11.426Z (6 months ago)
- Topics: api, api-rest, http, php-library, php72, rest-api
- Language: PHP
- Homepage: https://pixaye.github.io/chiven/
- Size: 1.69 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chiven






Simple library which allows you to build RESTful API fast, easy and flexible
# Installation
Install it via composer
```composer require pixaye/chiven```
# Usage
For start using Chiven\`s functionality, you should initialize its Request class as early, as you can (for example, you can init it in index.php)
Initializating from globals
```php
$request = new \Chiven\Http\Request();
$request->fromGlobals();
```
Initializating from custom variables
```php
$request = new \Chiven\Http\Request();
$files = array(
'file' => array (
'tmp_name' => '/tmp/df23fr32,
'name' => 'file.jpg',
'type' => 'image/jpeg',
'size' => 335057,
'error' => 0,
)
);
$headers = array(
'X-Test-Header: 1',
'X-Test-Header: 2',
);
$get = array(
'key' => 'value'
);
$post = array(
'key' => 'value'
);
$request->initialize($files, $get, $post, $headers)
```
Chiven allows you to work with files and headers in object oriented style. It builds objects of them and puts it in repositories: **FileRepostiory** and **HeaderRepository**
You can get them by calling **$request->getFiles()** and **$request->getHeaders()**
```php
$filesRepository = $request->getFiles();
$testFile = $filesRepository->findBy('name', 'test');
```
```php
$headersRepository = $request->getHeaders();
$testHeader = $filesRepository->findBy('name', 'X-Test-Header');
```
Both repositories have methods:
* findBy(**$criteria**, **$value**)
* findLast()
* findFirst()
* findAll()
* insert(*Insertable* **$object**)
* remove(**$criteria**, **$value**)
* set(*array* **$objects**)
To make Chiven process the request correctly and display the result in the desired format, there are **format classes**. At the moment, only JSON format is available to use.
```php
$request = new \Chiven\Http\Request();
$request->fromGlobals();
(new \Chiven\Bootstrap())->setFormat(new \Chiven\Format\Json());
//Request handling...
//Chiven response which returned by any script/controller/etc...
$response = new \Chiven\Http\Response\Response();
echo $chiven->getFormat()->responseDecorator($response);
```
This is how Chiven works, you can use example above and start creating your API with Chiven.