Okay. Sharing you a solution which I have used to call the Api from the plugin’s route, controller without using middleware.
Calling API from a Admin component **\src\plugins\plugin-name\admin\src\components\componentName\index.js**)
const response = await request('/plugin-name/route-name', {
method: 'POST',
body: {
prompt: prompt,
}
})
Create a route at this path **\src\plugins\plugin-name\server\routes\index.js** and add the below code
module.exports = [
{
method: 'POST',
path: '/route-name',
handler: 'controllerName.myFunction',
},
];
Create a controller at this path **\src\plugins\plugin-name\server\controllers\controllerName.js** and add the below code:
'use strict';
module.exports = ({ strapi }) => ({
async myFunction(ctx) {
// Your logic (Copy your Normal controller function code here)
},
});
I hope this can give you a better idea now ![]()