
====, (*1)
, (*2)
Install
composer install eden/server
, (*3)
====, (*4)
, (*5)
Introduction
Eden Server is an Express style web service. It allows all kinds of webframeworks to be developed because heavily relies on external middleware. A quick example of this usage is found below., (*6)
eden('server')
->route('*', function($request, $response) {
$response->set('body', 'Hello World!');
})
->render();
There are 3 kinds of middleware it accepts and are called during specific times during the response process., (*7)
Global Middleware
Global Middleware are called before any response is generated. Some examples of global middleware can be, (*8)
- Security - like CSRF checking, Captcha, CORS, HTPASSWD, etc.
- API - like Facebook Login, Paypal, etc.
- Utility - like geoip, localization, internationalization, etc.
You can simply add global middleware in this fashion., (*9)
eden('server')->add(function($request, $response) {
$response->set('body', 'Hello World!');
});
Route Middleware
Route Middleware are called when the request is formed right after the Global Middleware. To make a route available you will need the request method, desired route path and the callback handler., (*10)
You can simply add route middleware in this fashion., (*11)
eden('server')->route('POST', '/some/path/*/foo', function($request, $response) {
$response->set('body', 'Hello World!');
});
Routes can accept dynamic variables denoted as *
, described in the example route /some/path/*/foo
. These variables are accessable by calling $id = $request->get('variables', 0);
in your route handler callback. If your route is using a common request method like POST
, GET
, PUT
, DELETE
, there are wrapper methods recommended to use instead., (*12)
eden('server')->post('/some/path/*/foo', function($request, $response) {
$response->set('body', 'Hello World!');
});
eden('server')->get('/some/path/*/foo', function($request, $response) {
$response->set('body', 'Hello World!');
});
eden('server')->put('/some/path/*/foo', function($request, $response) {
$response->set('body', 'Hello World!');
});
eden('server')->delete('/some/path/*/foo', function($request, $response) {
$response->set('body', 'Hello World!');
});
For all the above methods you can also set the response by returning the string like below., (*13)
eden('server')->get('/some/path/*/foo', function($request, $response) {
return 'Hello World';
});
Error Middleware
Error Middleware are called when either the Global or the Route Middleware throws an Exception. You can simply add an error middleware in this fashion., (*14)
eden('server')->error(function(
$request,
$response,
$type,
$level,
$class,
$file,
$line,
$message
) {
$response->set('body', 'Hello World!');
});
====, (*15)
, (*16)
API
====, (*17)
, (*18)
add
Adds global middleware, (*19)
Usage
eden('server')->add(function $callback);
Parameters
-
function $callback
- The middleware handler
Returns Eden\Server\Index
, (*20)
Example
eden('server')->add(function($request, $response) {
$response->set('body', 'Hello World!');
});
====, (*21)
, (*22)
all
Adds routing middleware for all methods, (*23)
Usage
eden('server')->all(string $path, function $callback);
Parameters
-
string $path
- The route path
-
function $callback
- The middleware handler
Returns Eden\Server\Index
, (*24)
Example
eden('server')->all('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====, (*25)
, (*26)
child
Returns a new instance with the same configuration, (*27)
Usage
eden('server')->child();
Parameters
Returns Eden\Server\Index
, (*28)
====, (*29)
, (*30)
delete
Adds routing middleware for delete method, (*31)
Usage
eden('server')->delete(string $path, function $callback);
Parameters
-
string $path
- The route path
-
function $callback
- The middleware handler
Returns Eden\Server\Index
, (*32)
Example
eden('server')->delete('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====, (*33)
, (*34)
error
Adds error middleware, (*35)
Usage
eden('server')->error(function $callback);
Parameters
-
function $callback
- The middleware handler
Returns Eden\Server\Index
, (*36)
Example
eden('server')->error('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====, (*37)
, (*38)
get
Adds routing middleware for get method, (*39)
Usage
eden('server')->get(string $path, function $callback);
Parameters
-
string $path
- The route path
-
function $callback
- The middleware handler
Returns Eden\Server\Index
, (*40)
Example
eden('server')->get('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====, (*41)
, (*42)
getRequest
Returns a request object, (*43)
Usage
eden('server')->getRequest();
Parameters
Returns Eden\Registry\Index
, (*44)
====, (*45)
, (*46)
getResponse
Returns a response object, (*47)
Usage
eden('server')->getResponse();
Parameters
Returns Eden\Registry\Index
, (*48)
====, (*49)
, (*50)
getParent
Returns the parent server, (*51)
Usage
eden('server')->getParent();
Parameters
Returns Eden\Server\Index
, (*52)
====, (*53)
, (*54)
output
Evaluates the response in order to determine the output. Then of course, output it, (*55)
Usage
eden('server')->output(Eden\Registry\Index $response);
Parameters
-
Eden\Registry\Index $response
- The response object to evaluate
Returns Eden\Server\Index
, (*56)
Example
eden('server')->output($response);
====, (*57)
, (*58)
post
Adds routing middleware for post method, (*59)
Usage
eden('server')->post(string $path, function $callback);
Parameters
-
string $path
- The route path
-
function $callback
- The middleware handler
Returns Eden\Server\Index
, (*60)
Example
eden('server')->post('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====, (*61)
, (*62)
process
Starts to process the request, (*63)
Usage
eden('server')->process();
Parameters
Returns array
- with request and response inside, (*64)
====, (*65)
, (*66)
put
Adds routing middleware for put method, (*67)
Usage
eden('server')->put(string $path, function $callback);
Parameters
-
string $path
- The route path
-
function $callback
- The middleware handler
Returns Eden\Server\Index
, (*68)
Example
eden('server')->put('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====, (*69)
, (*70)
redirect
Browser redirect, (*71)
Usage
eden('server')->redirect(string $path);
Parameters
-
string $path
- Where to redirect to
Returns mixed
, (*72)
Example
eden('server')->redirect();
====, (*73)
, (*74)
render
Process and output, (*75)
Usage
eden('server')->render();
Parameters
Returns Eden\Server\Index
, (*76)
====, (*77)
, (*78)
route
Adds routing middleware, (*79)
Usage
eden('server')->route(string $method, string $path, function $callback);
Parameters
-
string $method
- The request method
-
string $path
- The route path
-
function $callback
- The middleware handler
Returns Eden\Server\Index
, (*80)
Example
eden('server')->route('POST', '/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====, (*81)
, (*82)
setParent
Returns if we were able to output something, (*83)
Usage
eden('server')->setParent(Eden\Server\Index $parent);
Parameters
-
Eden\Server\Index $parent
- The parent server
Returns Eden\Server\Index
, (*84)
Example
eden('server')->setParent($parent);
====, (*85)
, (*86)
success
Returns if we were able to output something, (*87)
Usage
eden('server')->success();
Parameters
Returns bool
, (*88)
====, (*89)
, (*90)
Contributing to Eden
Contributions to Eden are following the Github work flow. Please read up before contributing., (*91)
Setting up your machine with the Eden repository and your fork
- Fork the repository
- Fire up your local terminal create a new branch from the
v4
branch of your
fork with a branch name describing what your changes are.
Possible branch name types:
- bugfix
- feature
- improvement
- Make your changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")
Making pull requests
- Please ensure to run
phpunit
before making a pull request.
- Push your code to your remote forked version.
- Go back to your forked version on GitHub and submit a pull request.
- An Eden developer will review your code and merge it in when it has been classified as suitable.