How to consume ApiResource’s endpoint from Controller’s form?

So I have installed ApiPlatform on my project and have a Task.php entity on it as a resource.
How can I use my Task api resource’s endpoints when a form is submitted?

I am considering using httpclientinterface, but there is no way to retrieve submitted values without $form->handleRequest($request)

ProjectController.php

public function new(HttpClientInterface $client, Request $request): Response
    {
        $form = $this->createForm(TaskType::class);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $task = $form->getData();

            //trying to consume api endpoint here

            return $this->redirectToRoute('home');
        }

        return $this->render('pages/newtask.html.twig', [
            'form' => $form->createView(),
        ]);

    }

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *