0
votes

I am developing an API using resource controller in laravel. To call this api from my client i am using guzzle(my client is also laravel). For POST and GET requests it worked fine but for delete request it is showing below error.
enter image description here

My delete request is

$client = new Client();
$res = $client->delete('http://localhost:8017/opendemo_old/public/TestAPI/123456');

Below are my post and get request which are working fine.

$client = new Client();
$res = $client->request('POST', 'http://localhost:8017/opendemo_old/public/TestAPI', [
        'form_params' => [
            'field_name' => 'abcddd',
            'other_field' => '12344',
            'nested_field' => [
                'nested' => 'hello'
            ]
        ]
    ]);


$client = new Client();
$res = $client->request('GET', 'http://localhost:8017/opendemo_old/public/TestAPI/123'); <br/>

I am not getting what's the problem with delete request. I am using guzzle 6 and laravel 5.2(client & server).

1
Your API is returning a 500 error. There is something wrong with the delete route logic, not the client calling it.David Barker
@DavidBarker thanks for your comment. currently i did'nt wrote any logic in delete route it is under testing. actually it's an resource controller and the delete method is public function destroy($id) { // echo "Delete"; }prudhvi259

1 Answers

1
votes

Another way to DELETE request for Laravel.

$client = new Client();
$res = $client->post('http://localhost:8017/opendemo_old/public/TestAPI/123456', [
    'form_params' => [
        '_method' => 'DELETE'
    ]
]);