So if you go to the directory:
src/api/YOUR_ENDPOINT_NAME/controllers/YOUR_ENDPOINT_NAME.js. Open up that file and you can override any of the methods on the controller. Controllers have a number of methods that are automatically created when you create an api. These are: find(), findOne(), create(), update(), delete().
For an example, I have an api called article. When I created that endpoint, it automatically created the controller for me in: src/api/article/controllers/article.js
By default, this controller just looks like this:
'use strict';
/**
* article controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::article.article');
In here you can override any of those methods I mentioned above, so as an example, if you wanted to override the find() endpoint:
'use strict';
/**
* article controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::article.article', ({ strapi }) => ({
// Method 2: Wrapping a core action (leaves core logic in place)
async find(ctx) {
// some custom logic here
ctx.query = { ...ctx.query, local: 'en' }
// Calling the default core action
const { data, meta } = await super.find(ctx);
// some more custom logic
meta.date = Date.now()
return { data, meta };
},
}));
That’s pretty much it, the documentation for this is at this link (Backend customization - Controllers - Strapi Developer Docs). It also shows how you can add more methods to your controllers. You can also find the default controller code in the current version in the github repository (strapi/collection-type.js at master · strapi/strapi · GitHub) so you can copy whatever method you want to override to your file and modify it as you need. Hope this helps!