Skip to content

Conversation

@sebj54
Copy link
Contributor

@sebj54 sebj54 commented May 31, 2019

Hi there, me again 😁

I find your project very flexible but I missed just one feature: custom endpoints.

I made a very few changes to allow the adding of custom endpoints very easily. It can be done by following a few simple steps.

First, create a controller for your endpoint, like this one:

<?php namespace MyNamespace; // optional use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Tqdev\PhpCrudApi\Controller\CustomController; use Tqdev\PhpCrudApi\Middleware\Router\Router; class MyCustomController extends CustomController { protected function registerRoutes(Router $router) { $router->register('POST', '/custom/endpoint', [$this, 'customEndpoint']); } public function customEndpoint(ServerRequestInterface $request): ResponseInterface { // Insert logic for this endpoint return $this->responder->success(1); } }

The most important for this controller is that it should extends CustomController.

Then, the only thing left is to register this controller in the config:

$config = new Config([ 'username' => 'xxx', 'password' => 'xxx', 'database' => 'xxx', 'controllers' => 'records,openapi,custom:\\MyNamespace\\MyCustomController ', ]);

Tell me what you think!

@mevdschee
Copy link
Owner

mevdschee commented Jun 6, 2019

This is a nice addition, that deserves it's own config parameter. One extra question: Can we somehow support openapi specification for custom endpoints?

@sebj54
Copy link
Contributor Author

sebj54 commented Jun 6, 2019

That is a good question, I have actually no knowledge at all about openapi. I assume it describes every API route, especially parameters, right?

You're right about the dedicated config parameter, I will update that!

@mevdschee
Copy link
Owner

@sebj54 I would be very thankful if you would review/test the changes.

mevdschee added a commit that referenced this pull request Sep 3, 2019
@mevdschee
Copy link
Owner

I added customOpenApiBuilders as a config parameter.

@sebj54
Copy link
Contributor Author

sebj54 commented Sep 3, 2019

I confirm it works! Did not test the customOpenApiBuildersthough.

Sorry for the late answer, I spent a few hours trying to debug the issue I just posted (#573). I thought the "Route not found" error was related to the custom endpoints… 🤦‍♂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants