jonathandey / oc-jd-dingoapi

Dingo/API implementation for OctoberCMS
MIT License
16 stars 7 forks source link

$api->get() doesn't work as expected #3

Closed chrisiek closed 7 years ago

chrisiek commented 7 years ago

When I run http://developer.dev/api/home I don't get 'Got here.' Only prints 1 in the log.

The API_PREFIX is also set to 'api' .

This is my code:

$api->version('v1', ['prefix' => 'api'], function ($api) {
trace_log("1");
     $api->get('home', function () {
        trace_log('Got here.');
        return ['now' => microtime()];
    });
 });

Any idea what's going on?

The fact is that I didn't know how to implement the mentioned

 require realpath(__DIR__ . '/http/api/routes.php'); 

line. It surely needs some more explanation.

jonathandey commented 7 years ago

I have added a more detailed explanation to the Plugins README file.

Are you still unsure as to where to put this line?

chrisiek commented 7 years ago

The code is correct and your additional explanation was a real help because I realized that I didn't give a chance the code to finish execution of code and execute the closure by inserting dd("stopped here"); at the very end. I shouldn't have inserted this line at the end like this.

 $api->version('v1', ['prefix' => 'api'], function ($api) {
 trace_log("1");
     $api->get('home', function () {
        trace_log('Got here.');
         return ['now' => microtime()];
    });
 });
 dd("stopped here"); // remove a line like this