This is the application you start from. It gives you the directory layout, the config files and the
amsrafid console script, and it pulls in
the framework as a dependency.
If you are looking for the framework itself, meaning routing, the container, middleware, migrations and the token guard, it lives in its own repository and its README is the one that documents them.
composer create-project amsrafid/piper my-api
cd my-api
cp env.example.xml env.xml
php amsrafid migrateThen point a web server at public/. On Apache, public/.htaccess already handles the rewrite.
env.xml ships with an empty <key>. The framework refuses a request without one of at least 60
characters. That is deliberate, because a token signed with a guessable key is worse than no token
at all.
php -r "echo bin2hex(random_bytes(32));"Paste the result into <app><key> in env.xml, and fill in the database block below it while you
are there. env.xml is git-ignored. env.example.xml is the copy that gets committed, so keep
secrets out of it.
<debug> ships as false. Turn it on while you are building, since it is what puts the stack trace
in the response, and turn it back off before anything is reachable from outside.
app/
Console/Kernel.php your console commands
Exceptions/ your exception dispatcher
Http/
Controllers/ routes live here, by convention or by attribute
Middleware/
Kernel.php global, prefix and route middleware
Models/
config/ app, auth, database, path, request, storage
database/
migrations/ make:migration writes here
migrates.json what has been migrated
public/index.php the entry point
storage/
amsrafid the console script
Write a method. That is the whole step, the convention routes it:
namespace App\Http\Controllers;
class ShopController extends Controller
{
public function index()
{
return $this->response(['items' => []]); // GET /shop/index
}
}When the convention is not enough, say for a slug, a version prefix or a specific verb, declare it:
use Piper\Routing\Attributes\Get;
#[Get('/shop/{slug}')]
public function bySlug($slug)
{
return $this->response(['slug' => $slug]);
}Both styles work in the same controller. The framework README covers the rest of the attributes, along with middleware, migrations and the token guard.
php amsrafid make:controller Shop
php amsrafid make:model Order
php amsrafid make:migration create_orders_table
php amsrafid migrate
php amsrafid migration:status
php amsrafid storage:link
PHP 8.0 to 8.3.
A. M. Sadman Rafid, amsrafid.com · github.com/amsrafid
If you find a security problem, please email amsrafid@gmail.com rather than opening a public issue.
MIT.