tobyzerner / json-api-server

A JSON:API server implementation in PHP.
https://tobyzerner.github.io/json-api-server/
MIT License
63 stars 21 forks source link

Support invokable classes as action #111

Closed luceos closed 3 months ago

luceos commented 3 months ago

I am curious whether you'd be open to the ability for Endpoints to support Invokable classes. Although by default Closures are support, it would be great if you could simplify code even more by pushing logic into a separate class. For instance:

    public function endpoints(): array
    {
        return [
            Endpoint\Index::make('outbox')
                ->action(Action\OutboxAction::class)
                ->route('GET', '/{id}/outbox')
        ];
    }

Creating the respective Invokable class to another folder will clear out the Resource class definition, while still guaranteeing ease of tracing.

PS, amazing work Toby, been playing with this library these past few weeks and it's very much a welcome, fresh change to building an API server 👏

luceos commented 3 months ago

Disregard Toby, seems I was looking at a Flarum implementation 🙈