imageimage
Schedule a Call

Get in Touch

  • Email Now
    contact@indusvalley.io
  • Headquarters
    Long Meadows Road Bedminster, New Jersey, 07921 United States
Social Link
  • Instagram
  • LinkedIn
  • X
  • Facebook
  • Youtube
  • Home
  • Services
    • AI Development
      • Generative AI
      • Machine Learning
      • Predictive Analytics
    • Mobile App Development
      • iOS App Development
      • Android App Development
      • Cross Platform App Development
    • Web Development
    • Digital Marketing
      • SEO
      • Social Media Marketing
      • Performance Marketing
      • Content Marketing
    • Design
      • UI/UX Design
      • Logo & Branding
      • Video Animation
    • IT Staff Augmentation
    • Cloud Services
  • IVY
  • Chat With IVY
  • Portfolio
  • Blogs
  • About Us
  • Contact Us
imageimage
image
  • Home
  • Services
    • AI Development
      • Generative AI
      • Machine Learning
      • Predictive Analytics
    • Mobile App Development
      • iOS App Development
      • Android App Development
      • Cross Platform App Development
    • Web Development
    • Digital Marketing
      • SEO
      • Social Media Marketing
      • Performance Marketing
      • Content Marketing
    • Design
      • UI/UX Design
      • Logo & Branding
      • Video Animation
    • IT Staff Augmentation
    • Cloud Services
  • IVY
  • Portfolio
  • Blogs
  • About Us
  • Contact Us
  • Sun-Tue (9:00 am-7.00 pm)
  • infoaploxn@gmail.com
  • +91 656 786 53
Get in Touch
Schedule a CallLet's Talk

Developer Insights & Best Practices / Let’s Stop Writing the Same 5 Lines of Boilerplate

Let’s Stop Writing the Same 5 Lines of Boilerplate
8/6/2025 | Ateeb Khan

Let’s Stop Writing the Same 5 Lines of Boilerplate



```

 export const apiSlice = createApi({
 reducerPath: ’postsApi’,
 baseQuery: fetchBaseQuery({ baseUrl: ’/api’ }),
 tagTypes: [’Post’],
 endpoints: () => ({})
})

```

I deleted them with glee.

I replaced them with zero lines.

That felt good, so I wrote this rant.



We’ve all done it

Every team has that one folder: features/auth/api, features/users/api, features/comments/api…

Each file is a carbon copy of the last, except the string ’postsApi’ becomes ’commentsApi’.

We copy-paste, change two tokens, commit, and call it “scalable architecture”.

It’s not scalable. It’s busy-work.



Boilerplate is the tax we pay ourselves

I’m not talking about the unavoidable stuff like useState or console.log.

I’m talking about the self-imposed ceremony we invented to feel “enterprise”.

Every time we add a new model we:


  1. Create modelApi.ts
  2. Paste the same 5 lines
  3. Update two strings
  4. Write a test that asserts the file exists
  5. Call the sprint “done”

We burn story points on typing, not on thinking.



The hidden cost

Those five lines look harmless, but they spread like ivy:


●    Junior devs think they’re “following the pattern”, so they cargo-cult it into new modules.

●    PR reviewers rubber-stamp it (“looks consistent”).

●    Bundle size grows because tree-shaking can’t delete a file that’s imported everywhere.

●    Onboarding docs swell: “Make sure you create the api slice file…”

Suddenly your codebase has 200 apiSlice files and one actual endpoint.



Kill it with abstraction, not convention

I replaced the 200 files with one factory:

 

```

 // apiFactory.ts
export const createNamedApi = (name: string) =>
 createApi({
   reducerPath: name,
   baseQuery: fetchBaseQuery({ baseUrl: ’/api’ }),
   tagTypes: [name],
   endpoints: () => ({})
 })

```

Now adding a new domain is a one-liner:

```

 export const postsApi = createNamedApi(’posts’)

```

No file, no copy-paste, no typo in reducerPath.

The tests? They test the factory once, not every file.



Abstraction is scary—duplication is scarier

“But what if we need different baseQuery options later?”

Then we’ll pass an optional config object.

“What if we need custom tagTypes?”

Then we’ll accept an override.

We can evolve the helper faster than we can delete 200 stale files.

YAGNI is not an excuse to multiply garbage.



Your linter can help

Add an eslint rule:

```

 "no-restricted-syntax": [
 "error",
 {
   "selector": "CallExpression[callee.name=’createApi’]",
   "message": "Use createNamedApi() instead of inline createApi()"
 }
]

```

Now the machine stops the pattern from spreading.



What to do today

  1. Find the five-line clones with rg "reducerPath.Api" -g ’.ts’ | wc -l.
  2. Extract a helper.
  3. Delete the clones.
  4. Push, watch CI go green, do a little dance.



Boilerplate isn’t architecture—it’s procrastination

Next time you’re about to create features/unicorns/api, ask yourself:

“Am I solving a real problem, or just avoiding the real problem?”

Stop writing the same five lines.

Start deleting them.

Your future self will git-blame you—and smile.

 

Related Blogs

Explore More
How I Fixed My Flutter Dependency Chaos (And Made My App Faster)
  • September 09, 2025

How I Mastered Flutter Dependencies and Made My App Super Scalable

Node.js 101: How to Build Your First HTTP Server
  • September 03, 2025

Node.js 101: How to Build Your First HTTP Server

Type-Safe API Calls in TypeScript with Just 30 Lines of Code
  • August 12, 2025

Type-Safe API Clients in 30 Lines of TypeScript

Our Trusted
Partner.

Unlock Valuable Cloud and Technology Credits

Imagine reducing your operational costs by up to $100,000 annually without compromising on the technology you rely on. Through our partnerships with leading cloud and technology providers like AWS (Amazon Web Services), Google Cloud Platform (GCP), Microsoft Azure, and Nvidia Inception, we can help you secure up to $25,000 in credits over two years (subject to approval).

These credits can cover essential server fees and offer additional perks, such as:

  • Google Workspace accounts
  • Microsoft accounts
  • Stripe processing fee waivers up to $25,000
  • And many other valuable benefits

Why Choose Our Partnership?

By leveraging these credits, you can significantly optimize your operational expenses. Whether you're a startup or a growing business, the savings from these partnerships ranging from $5,000 to $100,000 annually can make a huge difference in scaling your business efficiently.

The approval process requires company registration and meeting specific requirements, but we provide full support to guide you through every step. Start saving on your cloud infrastructure today and unlock the full potential of your business.

exclusive-partnersexclusive-partners
E-Commerce

Shopify

Hosting

Hostinger

Technology

Sentry

CMS

Hubspot

MARKETING

Semrush

HOSTING

Namecheap

Productivity

Evernote

Hosting

Bluehost

Success Stories

Explore More

Fynder.AI

Underdog Apparel

Toast DXB

Let's TALK

Let's TALK and bring your ideas to life! Our experienced team is dedicated to helping your business grow and thrive. Reach out today for personalized support or request your free quote to kickstart your journey to success.

Connect Us
Contact Now
DIGITAL PRODUCTUI/UX DESIGNDIGITAL STUDIOBRANDING DESIGNUI/UX DESIGNEMAIL MARKETINGBRANDING DESIGNUI/UX DESIGNEMAIL MARKETING
DIGITAL PRODUCTUI/UX DESIGNDIGITAL STUDIOBRANDING DESIGN

Subscribe our newsletter

Company

  • About Us
  • Portfolio
  • Blogs
  • IVY
  • Services
  • Contact Us
UI/UX DESIGN
EMAIL MARKETING
BRANDING DESIGN
UI/UX DESIGN
EMAIL MARKETING

Our Services

  • AI Development
  • Web Development
  • Mobile App Development
  • Digital Marketing
  • IT Staff Augmentation
  • Facebook
  • Youtube
  • X
  • Linkedin
  • Instagram
footer-logo
  • Email Now
    contact@indusvalley.io

Copyright © 2025 Indus Valley Technologies | All rights reserved ®

Terms & ConditionsPrivacy Policy