vendredi 25 octobre 2019

Lumen - Call other controller method and get response

In order to add the ability of bulk API requests to my api I have added a new method to one my controllers.
The method takes as input an array of objects and calls another method in the same controller (which may throw an exception).
see the following code:

       foreach ($objects as $object) {
            $request = (array)$object;
            $request = Request::create('/someinternalurl', 'POST', $request);
            $response = app()->dispatch($request);
            $responses[] = json_decode($response->getContent());
        }

the problem is that for 10 objects for example, this code takes about 15 seconds.
In addition i have tried to search for other solutions, but all i found seems to result
the same respone time or many changes to my API.

Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire