meilisearch-php icon indicating copy to clipboard operation
meilisearch-php copied to clipboard

Add a method to get the task endpoint

Open tacman opened this issue 9 months ago • 6 comments

There is a method in the client index that returns the index endpoint.

I would like a similar method for the task endpoint, although I'd prefer that the method name be more explicit. But I'd be okay with just having access to it.

$taskApi = $client->getTasksEndpoint();
$taskApi->get($taskUid);

In short, I'd like a way to access Tasks in the HandlesTasks trait.

    protected Tasks $tasks; /* access this from the application */

    public function getTask($uid): array
    {
        return $this->tasks->get($uid);
    }

tacman avatar Mar 06 '25 12:03 tacman

Why $client->getTask(id) isn't enough for you? Or are you referring to that something is missing?

norkunas avatar Mar 06 '25 14:03 norkunas

Because all of the calls are quite verbose and come from the client object. It would be clearer for me to know which API endpoint I'm calling. I don't think anything is missing, so mostly DX.

I'm refactoring all my code that to use $client->index() instead of $client->getIndex(), which had caused me all sorts of chicken-and-egg grief. I'm also monitoring tasks much closer, so with access to the tasks object there would be less code completion than with the client object.

tacman avatar Mar 06 '25 14:03 tacman

Yeah, i agree that there are way too much methods on a single client :) but given getTask method to me it's clear that you are calling tasks endpoint :)

I remember sometime ago that I suggested a similar way to split things, but still somebody must have some time to come up with a PR.

norkunas avatar Mar 06 '25 14:03 norkunas

well, yes, for an expert it's clear. For a newcomer to the library, it's less clear.

A HUGE thing that would help is if a Task object were returned instead of simply array.

tacman avatar Mar 06 '25 15:03 tacman

well, yes, for an expert it's clear. For a newcomer to the library, it's less clear.

A HUGE thing that would help is if a Task object were returned instead of simply array.

#703 :)

norkunas avatar Mar 06 '25 15:03 norkunas

@tacman see #735

norkunas avatar Apr 10 '25 03:04 norkunas