apitte icon indicating copy to clipboard operation
apitte copied to clipboard

Method signature instead of RequestParameters

Open tprochazka opened this issue 4 years ago • 1 comments

I'm migrating my app from using great Drahak\Restful, because this library is sadly not maintained. It was able to automatically map request to method parameters and obtain type and default value from it.

So instead of

/**
 * @Path("/users")
 * @Method("GET")
 * @RequestParameters({
 *      @RequestParameter(name="page", in="query", type="int")
 * })
 */
public function index(ApiRequest $request, ApiResponse $response): ApiResponse {

	$page = $request->getParameter("page", 1);

Was possible to just provide type and default value by signature like that

/**
 * @Path("/users")
 * @Method("GET")
 */
public function index(int $page = 1): ApiResponse {

Only additional attributes can be provided by annotation. Why so the verbose approach was used by Apitte?

tprochazka avatar Feb 01 '21 01:02 tprochazka

Hi. Unfortunately no, this relies on PSR-7 + middlewares, so you receive request object as parameter. You can drain whatever you need from ApiRequest, URL parameters, query parameters, headers, whatever.

f3l1x avatar Feb 01 '21 11:02 f3l1x