server icon indicating copy to clipboard operation
server copied to clipboard

it don't work with quickstart, it return 404 not found, my route not correct ?

Open weishuiliang opened this issue 3 years ago • 1 comments

class TennisProcedure extends Procedure
{
    /**
     * The name of the procedure that will be
     * displayed and taken into account in the search
     *
     * @var string
     */
    public static string $name = 'tennis';

    /**
     * Execute the procedure.
     *
     * @param Request $request
     *
     * @return array|string|integer
     */
    public function ping(Request $request)
    {
        return "pong";
    }
}

and my route in api.php

Route::rpc('/v1/endpoint', [TennisProcedure::class])->name('rpc.endpoint');

and my request:

request url:
http://127.0.0.1:8006/api/v1/endpoint

request  body
{
    "jsonrpc": "2.0",
    "method": "tennis@ping",
    "id": 1
}

weishuiliang avatar Jun 23 '22 03:06 weishuiliang

Hi @weishuiliang I checked and my new installation works well with the example you gave. Is it possible that you put the route declaration in the sanctum group and pass it without its key?

My routes file looks like this:

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Procedures\TennisProcedure;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::rpc('/v1/endpoint', [TennisProcedure::class])->name('rpc.endpoint');

Checked out curl and tinker

\Illuminate\Support\Facades\Http::withBody('{"jsonrpc":"2.0","method":"tennis@ping","id":1}', 'application/json')->post('http://127.0.0.1:8000/api/v1/endpoint')->json();

Could you give more information on how to reproduce the problem? As well as the output of all registered routes (command output) artisan route:list

tabuna avatar Jul 02 '22 20:07 tabuna