Skip to content

Feature request: Api wrapper class #60

@Radiergummi

Description

@Radiergummi

Hey there, I'm quite new to Craft, so if this won't fit in the conventions, be free to close this issue.
Coming mainly from Laravel, the syntax to define endpoints seems a little off to me. I'd favor to use something like $api->addEndpoint(string $uri, Closure $handler);. On the one hand, that'd make IDE hints a tad more useful. On the other, it'd be nice to have a $api->addCollection(string $uri, Closure $endpointsCallback);, too. Within this $endpointsCallback, one could define additional endpoints sharing the collection URI as a prefix. That'd allow for conveniently splitting the elementapi.php into multiple files once the number of endpoints grows.
I've made a little proof of concept class which you'll find in in this gist, including usage examples. This could obviously be extended in functionality.

What's your opinion on this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions