Download the PHP package hrishikesh214/php-api without Composer
On this page you can find all versions of the php package hrishikesh214/php-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hrishikesh214/php-api
More information about hrishikesh214/php-api
Files in hrishikesh214/php-api
Package php-api
Short Description Helps easily build RESTFul Api in PHP
License GPL-3.0-or-later
Informations about the package php-api
PHP
API
Index
- Installation
- Documentation
- Creating Endpoint
- Passing URL Parameters
- Post Parameters
- API Tracer
- Setting Error Handlers
- External Routes
Installation
And then in your file
Configurations
Before getting into PHPAPI
we have to make some configs
In your root directory, create .htaccess
file and paste following code
Documentation
Creating a client
You can also pass base address
All child endpoints will be access after api/
Running Client
This $client->run()
returns response string, so you can store it in variable for further process or directly print it as response
Creating an Endpoint
Only some request methods are allowed : 'PUT', 'POST', 'DELETE', 'PATCH', 'GET', 'PURGE'
mount
returns boolean value about whether endpoint is mounted successfully or not
Passing URL Parameters
Client
will automatically pass url parameters to the response function
example is given below
URI Parameters are directly passed to the responder function in an associative array according to the key passed in parameter
All other posted
parameters will automatically get stored in $_POST
NOTE
If parameter is define while mounting but not passes then it is given a null value
POST Endpoint
Trace Whole API
You can trace whole API Client with detailed configs of all endpoints mounted with a function
If Above value is true final api result will also included api configs
This Also includes Requested configs
Example output:-
In above example result will contain result coming from API
Setting Request Errors
There is a default error handler but you change it!
404
405
External Routes
Importing Routes from external file
You can also define routes in external file all you need is to use Helper
Class.
For example (folder structure):-
In above code $config['base']'
will be act as base to all routes present in this file.
$routes
will contain all routes.
Please maintain format else code will not work!