Last active
September 2, 2020 12:46
-
-
Save pixelbrackets/8d63ea6259da5576a269026dfc8ccfcf to your computer and use it in GitHub Desktop.
waterpipe-example-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/../vendor/autoload.php'; | |
/** | |
* Waterpipe: https://packagist.org/packages/elementaryframework/water-pipe | |
* | |
* Examples calls: | |
* http 127.0.0.1:8080/ # GET homepage | |
* http 127.0.0.1:8080/build/ token=foo # POST JSON Build endpoint | |
**/ | |
use ElementaryFramework\WaterPipe\WaterPipe; | |
use ElementaryFramework\WaterPipe\HTTP\Request\Request; | |
use ElementaryFramework\WaterPipe\HTTP\Response\Response; | |
use ElementaryFramework\WaterPipe\HTTP\Response\ResponseStatus; | |
use ElementaryFramework\WaterPipe\HTTP\Response\ResponseHeader; | |
$app = new WaterPipe; | |
// homepage | |
$app->get('/', static function (Request $request, Response $response) { | |
$response->sendHtml('Endpoints: <ul><li>/build</li></ul>'); | |
}); | |
// build endpoint | |
$app->post('/build', static function (Request $request, Response $response) { | |
$data = $request->getBody()->toArray(); | |
$response->sendJson([ | |
'success' => true, | |
'token' => $data['token'] | |
]); | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: This requires redirecting all request to index.php → https://gist.github.com/pixelbrackets/8ba866dcb207b461f0ed0bc5af45927b