cloudcreativity / laravel-json-api

JSON API (jsonapi.org) package for Laravel applications.
http://laravel-json-api.readthedocs.io/en/latest/
Apache License 2.0
780 stars 109 forks source link

JSON API 'default' does not exist #550

Closed masumetc closed 3 years ago

masumetc commented 4 years ago

I am trying to send a http request to remote server

` $guzzleClient = new Client(['base_uri' => 'https://eu.api.tokengateway.io/getToken']); $client = json_api()->client($guzzleClient); $response = $client->query('data', [ 'contractaddress' => '0x5b86a33f0c232fe909eb4602a9d039072869d915', 'apikey' => 'q9PdaWuD4j6DK6vsUgehhL8pgarSrS9m', ]);

    return response()->json($response);`

Here is my ajaz code

`$(function(){ $("#CheckApi").on("submit", function(e){ e.preventDefault(); var form = $(this); var url = form.attr("action"); var type = form.attr("method"); var data = form.serialize();

        $.ajax({

            url: url,
            data: data,
            type: type,
            dataType: "JSON",
            success: function(response){
               console.log(response)
            },

        });

    });

});`

Here is my api.php route

Route::get('api','App\Http\Controllers\Api\ApiController@api')->name('api');

I have got this(JSON API 'default' does not exist) error

lindyhopchris commented 4 years ago

Sorry but none of the above makes any sense to me. I'm not sure what you're trying to do.

That error message means you haven't defined a JSON API set of configuration called 'default'. You can read all about that here: https://laravel-json-api.readthedocs.io/en/latest/basics/api/

If you've generated an API but called it something different to 'default', you'll need to follow the instructions in that chapter about setting the name of the default API.

ben221199 commented 3 years ago

@masumetc Do you have a configuration file json-api-default.php in your configuration folder? You are using $client = json_api()->client($guzzleClient);. Because you are calling json_api() without a parameter, you it will use json-api-default.php. If you are calling json_api('myApiName'), then it will use json-api-myApiName.php.

lindyhopchris commented 3 years ago

Closing this due to lack of response; believe the answers above probably solved the problem!