// Index resource, just routing, no HTTP method handling.
class IndexResource extends Resource {
public function __construct(Application $app) {
// ...
}
// Route nested resources for any request
public function any(Request $request) {
// Static path:
$this->path(
CollectionResource::Path, new CollectionResource($this)
);
}
}
class CollectionResource extends Resource {
const Path = 'items';
// Parent resource type constraint, you can access
// parent data using IndexResource API:
public function __construct(IndexResource $parent) {
//...
}
// Route nested resources for any HTTP method:
public function any(Request $request) {
// Regexp pattern for URI segment:
$this->match(ItemResource::Pattern, new ItemResource($this));
}
// Or handle GET
public function GET(Request $request) {
// ...
}
// Or POST maybe
public function POST(Request $request) {
// ...
}
}
class ItemResource extends Resource {
const Pattern = '(\d+)';
public function __construct(CollectionResource $parent) {
// ...
}
public function any(Request $request, $prefix, $id) {
$this->item = Item::find($id);
}
public function GET(Request $request) {
return JSON::string($this->item);
}
}
It's not about routers + controllers etc, it's just resources + delegation to nested resources:
I think the "Build & Deploy" for configuration management is the right thing, but it looks like Ansible is not very good tool to implement it (and honestly, I don't know any mainstream tool that is really good at it).
I was trying to implement it as follows:
- part of a role is executed locally, building all the configuration files from templates (build); - configuration built locally is rsynced into dedicated directory on target server, deleting unnecessary files etc (sync); - part of a role is executed remotely, setting up symlinks from real configuration paths into synced dir and running all necessary actions (restarting services etc).
Yes, it's possible to write Ansible playbooks and roles that way, but in practice you are permanently struggling with the default Ansible playbooks and roles organizational structure.
I believe the only devops tool that really supports this style of things now is Nix and all the infrastructure around (and conceptually it's perfect, but in practice it has it's drawbacks).