1. Go to this page and download the library: Download vlucas/bulletphp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vlucas / bulletphp example snippets
imply build the application around your URLs */
$app = new Bullet\App();
$app->path('/', function($request) {
return "Hello World!";
});
$app->path('/foo', function($request) {
return "Bar!";
});
/* Run the app! (takes $method, $url or Bullet\Request object)
* run() always return a \Bullet\Response object (or throw an exception) */
$app->run(new Bullet\Request())->send();
$app = new Bullet\App(array(
'template.cfg' => array('path' => __DIR__ . '/templates')
));
// 'blog' subdirectory
$app->path('blog', function($request) use($app) {
$blog = somehowGetBlogMapper(); // Your ORM or other methods here
// 'posts' subdirectory in 'blog' ('blog/posts')
$app->path('posts', function() use($app, $blog) {
// Load posts once for handling by GET/POST/DELETE below
$posts = $blog->allPosts(); // Your ORM or other methods here
// Handle GET on this path
$app->get(function() use($posts) {
// Display all $posts
return $app->template('posts/index', compact('posts'));
});
// Handle POST on this path
$app->post(function() use($posts) {
// Create new post
$post = new Post($request->post());
$mapper->save($post);
return $this->response($post->toJSON(), 201);
});
// Handle DELETE on this path
$app->delete(function() use($posts) {
// Delete entire posts collection
$posts->deleteAll();
return 200;
});
});
});
// Run the app and echo the response
echo $app->run("GET", "blog/posts");