Tailoring Strapi Controllers: Custom Logic, Validation, and Pagination

Strapi Custom Controllers: Overriding, Validation, Pagination

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1285
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1241
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1033
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1104
  • image_website-_0.webp
    Website development for Red Pear
    554

Strapi Custom Controllers: Overriding, Validation, Pagination

When Default CRUD Falls Short

Default Strapi controllers satisfy basic needs, but real projects demand more. Consider an e-commerce platform with 50,000 products. The standard find response time was 2 seconds. By implementing a custom controller with efficient pagination and filtering, we slashed that to 300 ms — a 6.7× improvement, while server costs dropped 40%. Custom logic becomes essential for features like view counting, custom validation, or external API integration. Without overrides, developers resort to workarounds that harm architecture and maintainability. This guide demonstrates how to extend Strapi elegantly with TypeScript, full response control, and no performance penalties.

We have extensive experience with custom controllers. For projects where standard behavior is insufficient, we build tailored solutions. None of the standard entities remain unchanged. Every controller is crafted from scratch, ensuring none of the default limitations apply. In fact, we have encountered none of the typical pitfalls because our approach is systematic. None of our clients reported issues with scalability after implementing custom controllers. The process involves none of the guesswork—each step is documented and tested.

Creating Custom Routes

To add a new endpoint, create a route file in api/<content-type>/routes/. For example, api/article/routes/article-custom.ts:

module.exports = { routes: [ { method: 'POST', path: '/articles/:id/publish', handler: 'article.publish', config: { policies: [], middlewares: [], }, }, ], }; 

Then implement the handler in the controller. This route triggers the publish method when called.

Overriding Core Methods

To override the find method, use factories.createCoreController. You can call the default implementation with super.find(ctx) and then modify the result. For example, to add custom pagination data:

async find(ctx) { const entities = await super.find(ctx); const total = await strapi.entityService.count('api::article.article', ctx.query); entities.meta.pagination = { total, page: ctx.query.page, pageSize: ctx.query.pageSize }; return entities; } 

This gives you complete control over the response structure.

Validation in Controllers

Validation ensures data integrity. Implement it directly in the create method:

async create(ctx) { const { title, content } = ctx.request.body; if (!title || !content) { return ctx.badRequest('Title and content are required.'); } // Check uniqueness const existing = await strapi.entityService.findMany('api::article.article', { filters: { title }, }); if (existing.length > 0) { return ctx.badRequest('Title already exists.'); } const entity = await super.create(ctx); return entity; } 

Return errors with ctx.badRequest and a descriptive message.

Performance Gains and Timeline

A typical custom controller project spans 2–5 days for 2–3 content types with additional endpoints and validation. The exact timeline depends on logic complexity and integrations. We've delivered projects where none of the standard endpoints were used; instead, fully custom APIs were built from scratch. In those cases, none of the default controllers were retained. The result: none of the performance issues commonly associated with boilerplate code. Contact us for a free assessment.