-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow registration of custom actions #36
Comments
Now technically possible with custom endpoints in v1.0. Providing some Action endpoints out of the box planned for v1.1 |
I'd be interested in this for some of our use-cases. Can you expand on how it is already possible with custom endpoints? |
Create a new implementation of class MyAction implements EndpointInterface
{
public static function make(): static
{
return new static();
}
public function handle(Context $context): ?ResponseInterface
{
// Endpoint to handle POST /{resource}/my-action
$segments = explode('/', $context->path());
if (count($segments) !== 2 || $segments[1] !== 'my-action') {
return null;
}
if ($context->method() !== 'POST') {
throw new MethodNotAllowedException();
}
// Do stuff with $context->resource, $context->body(), etc
return new Response(204);
}
} Then just add a new instance of your endpoint to the public function endpoints()
{
return [Endpoint\Show::make(), MyAction::make()];
} For 1.1 I'm planning to add generic action endpoints that you can instantiate with an action name and a handler function. |
For implementing behavior not defined by the spec.
Something like:
Call via:
The text was updated successfully, but these errors were encountered: