Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elementaryframework/waterpipe
URL routing framework, requests/responses handler, and HTTP client for PHP
https://github.com/elementaryframework/waterpipe
composer http http-client php php7 request response responses-handler url-rewrite url-router
Last synced: about 1 month ago
JSON representation
URL routing framework, requests/responses handler, and HTTP client for PHP
- Host: GitHub
- URL: https://github.com/elementaryframework/waterpipe
- Owner: ElementaryFramework
- License: mit
- Created: 2018-06-03T00:00:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-02T11:36:36.000Z (over 3 years ago)
- Last Synced: 2024-11-12T02:10:23.694Z (about 1 month ago)
- Topics: composer, http, http-client, php, php7, request, response, responses-handler, url-rewrite, url-router
- Language: PHP
- Homepage:
- Size: 190 KB
- Stars: 25
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
![WaterPipe Logo](assets/banner.png)
# WaterPipe
[![downloads](https://img.shields.io/packagist/dt/elementaryframework/water-pipe?style=for-the-badge&logo=packagist)](https://packagist.org/packages/elementaryframework/water-pipe)
[![downloads](https://img.shields.io/packagist/v/elementaryframework/water-pipe?style=for-the-badge&logo=packagist)](https://packagist.org/packages/elementaryframework/water-pipe)
[![downloads](https://img.shields.io/github/repo-size/ElementaryFramework/WaterPipe?style=for-the-badge&logo=github)](https://github.com/ElementaryFramework/WaterPipe)
[![downloads](https://img.shields.io/github/license/ElementaryFramework/WaterPipe?style=for-the-badge&logo=github)](https://github.com/ElementaryFramework/WaterPipe/blob/master/LICENSE)A powerful routing framework and requests/responses handler for PHP
WaterPipe is a library which allows you to easily handle HTTP requests and responses with PHP, giving you all the power
to build a fully RESTful API, to create a routing framework for your web application, etc...## Example
```php
get("/", function (Request $req, Response $res) {
$res->sendHtml("Welcome to my web app ! Click here to login");
});// Add a new route to the pipe with HTTP GET method (the login page)
$root->get("/login", function (Request $req, Response $res) {
$res->sendFile("./pages/login.html", ResponseStatus::OkCode);
});// Add a new route to the pipe with HTTP POST method (the login page form validation)
$root->post("/login", function (Request $req, Response $res) {
// Get $_POST values
$body = $req->getBody();
$username = $body["username"];
$password = $body["password"];if (validate_username($username) && validate_password($password)) {
// Checks if the client access this route with an AJAX request
if ($req->isAjax()) {
$res->sendJson(array(
"success" => true
));
} else {
// Redirect the user to the members page
$res->redirect("/members/{$username}");
}
} else {
// Checks if the client access this route with an AJAX request
if ($req->isAjax()) {
$res->sendJson(array(
"success" => false
));
} else {
// Redirect the user to the members page
$res->redirect("/login");
}
}
});// Add a new route to the pipe with HTTP GET method (the member's dashboard page)
$root->get("/members/:username", function (Request $req, Response $res) {
$res->sendHtml("Welcome to your dashboard {$req->uri['username']} !");
});// Add a new HTTP error handler (the 404 Not Found Error)
$root->error(ResponseStatus::NotFoundCode, function (Request $req, Response $res) {
$res->sendText("404 Error: Not Found.", ResponseStatus::NotFoundCode);
});// Finally... Run the pipe
$root->run();
```## Features
- Highly designed to quickly create routes for MVC applications and REST services ;
- Object Oriented HTTP [requests](https://github.com/ElementaryFramework/WaterPipe/blob/master/src/WaterPipe/HTTP/Request/Request.php) and [responses](https://github.com/ElementaryFramework/WaterPipe/blob/master/src/WaterPipe/HTTP/Response/Response.php) management ;
- Full support for HTTP methods: GET, POST, PUT, DELETE, HEAD, PATCH and OPTIONS ;
- Easily handle common HTTP errors (404, 500) ;
- Designed to work with frontend frameworks like React.js, AngularJS, Vue.js, etc... with AJAX support## Installation
You can install **WaterPipe** in your project with [composer](http://getcomposer.org):
```sh
composer require elementaryframework/water-pipe
```Once installed, you can access the **WaterPipe** api through the `ElementaryFramework\WaterPipe` namespace.
## How to use ?
New to **WaterPipe** ? Learn how to build routing frameworks and REST services by browsing our [wiki](https://github.com/ElementaryFramework/WaterPipe/wiki).
### Additional resources and tutorials
- [How to create a RESTful API with PHP and the Elementary Framework](https://dev.to/na2axl/how-to-create-a-restful-api-with-php-and-the-elementary-framework-30ij) written by @na2axl on dev.to
## Donate
Liking Elementary Framework? Help us continue to maintain it and provide you better support and awesome functionalities with a small donation!
[![Donate PayPal Button](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AGAQAC3W4ZRMA&source=url)
## License
© Copyright 2018-2020 Aliens Group.
Licensed under MIT ([read license](https://github.com/ElementaryFramework/WaterPipe/blob/master/LICENSE))