====
composer install eden/server
====
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.
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.
Global Middleware are called before any response is generated. Some examples of global middleware can be
- 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.
eden('server')->add(function($request, $response) {
$response->set('body', 'Hello World!');
});
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.
You can simply add route middleware in this fashion.
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.
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.
eden('server')->get('/some/path/*/foo', function($request, $response) {
return 'Hello World';
});
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.
eden('server')->error(function(
$request,
$response,
$type,
$level,
$class,
$file,
$line,
$message
) {
$response->set('body', 'Hello World!');
});
====
====
Adds global middleware
eden('server')->add(function $callback);
function $callback
- The middleware handler
Returns Eden\Server\Index
eden('server')->add(function($request, $response) {
$response->set('body', 'Hello World!');
});
====
Adds routing middleware for all methods
eden('server')->all(string $path, function $callback);
string $path
- The route pathfunction $callback
- The middleware handler
Returns Eden\Server\Index
eden('server')->all('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====
Returns a new instance with the same configuration
eden('server')->child();
Returns Eden\Server\Index
====
Adds routing middleware for delete method
eden('server')->delete(string $path, function $callback);
string $path
- The route pathfunction $callback
- The middleware handler
Returns Eden\Server\Index
eden('server')->delete('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====
Adds error middleware
eden('server')->error(function $callback);
function $callback
- The middleware handler
Returns Eden\Server\Index
eden('server')->error('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====
Adds routing middleware for get method
eden('server')->get(string $path, function $callback);
string $path
- The route pathfunction $callback
- The middleware handler
Returns Eden\Server\Index
eden('server')->get('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====
Returns a request object
eden('server')->getRequest();
Returns Eden\Registry\Index
====
Returns a response object
eden('server')->getResponse();
Returns Eden\Registry\Index
====
Returns the parent server
eden('server')->getParent();
Returns Eden\Server\Index
====
Evaluates the response in order to determine the output. Then of course, output it
eden('server')->output(Eden\Registry\Index $response);
Eden\Registry\Index $response
- The response object to evaluate
Returns Eden\Server\Index
eden('server')->output($response);
====
Adds routing middleware for post method
eden('server')->post(string $path, function $callback);
string $path
- The route pathfunction $callback
- The middleware handler
Returns Eden\Server\Index
eden('server')->post('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====
Starts to process the request
eden('server')->process();
Returns array
- with request and response inside
====
Adds routing middleware for put method
eden('server')->put(string $path, function $callback);
string $path
- The route pathfunction $callback
- The middleware handler
Returns Eden\Server\Index
eden('server')->put('/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====
Browser redirect
eden('server')->redirect(string $path);
string $path
- Where to redirect to
Returns mixed
eden('server')->redirect();
====
Process and output
eden('server')->render();
Returns Eden\Server\Index
====
Adds routing middleware
eden('server')->route(string $method, string $path, function $callback);
string $method
- The request methodstring $path
- The route pathfunction $callback
- The middleware handler
Returns Eden\Server\Index
eden('server')->route('POST', '/some/*/path', function($request, $response) {
$response->set('body', 'Hello World!');
});
====
Returns if we were able to output something
eden('server')->setParent(Eden\Server\Index $parent);
Eden\Server\Index $parent
- The parent server
Returns Eden\Server\Index
eden('server')->setParent($parent);
====
Returns if we were able to output something
eden('server')->success();
Returns bool
====
Contributions to Eden are following the Github work flow. Please read up before contributing.
##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.