Request vs. useFetchClient?

The tutorial plugin on youtube (https://www.youtube.com/watch?v=hh1VIQVXnAw&list=PL7Q0DQYATmvjd5D57P8CN0_xp_HsRd3wn&index=6), as well as the related code (plugin-dev-101-strapi-v4-complete/src/plugins/todo/admin/src/api/todo.js at main · PaulBratslavsky/plugin-dev-101-strapi-v4-complete · GitHub) use the module {request} from “@strapi/helper-plugin”. However it looks like at this point {request} has been deprecated and the examples have not been updated. I have not yet been able to make my example work with useFetchClient. There seem to be other questions on the forums about this: Give me some use case example about how to useFetchClient, which have no answer. Is there anyone that managed to make it work? Seems like it would be important to update the docs / tutorials if the key API is getting deprecated.

This topic has been created from a Discord post (1246094438787186779) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

Hello.

I do not know how is the tutorial, but I uses the following code on my custom plugins.

import { useFetchClient } from '@strapi/helper-plugin';

// on front-end component
// ...
const { get } = useFetchClient();

// request regular collections from content manager
get("/content-manager/collection-types/plugin::users-permissions.user?populate=*")

// request custom routes
get(`my-plugin/payments/to-do`)

Yes, that tutorial was made before useFetchCliend hook, this is somehting you should use moving forward.

Thank you for the answer. I am aware of that (ONLY because i get a warning original code flagged the deprecated API). There is no explanation on HOW to use the hook, nor proper documentation on the new API. With some tweaks and hours of debugging, I managed to make it work, but it was harder than necessary.

Thank you for your feedback, we do have contributor docs for developers, but you are right it is not easily found. https://contributor.strapi.io/docs/core/helper-plugin/hooks/use-fetch-client

aah that really helps, thanks!

Aah that really helps, thanks!