Feature request: Api wrapper class #146
Unanswered
Radiergummi
asked this question in
Ideas
Replies: 1 comment
-
Thanks for the suggestion! That’s certainly an elegant way of defining endpoints so I’m not against it, but it’s not really feasible right now, because plugin settings files get loaded before the plugin has even been instantiated. I’ll leave the issue open though, as in the long run it would be nice if we could come up with a way to make it possible. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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 theelementapi.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?
Beta Was this translation helpful? Give feedback.
All reactions