DEV Community

Yass1n
Yass1n

Posted on

bro.js v2.3.0: Simpler Routes, Smart Language Support, and Auto API Docs

When building an API framework, the hardest part is keeping code simple while making sure it doesn't break in production.

With bro.js v2.3.0, we focused on removing clutter from your route files and making everyday tasks—like handling multiple languages and documenting endpoints—as easy as possible.

Here is a quick look at what changed.


1. Cleaner, Flatter Route Validation

In earlier versions, you had to wrap your validation rules in a nested schema object:

// ❌ Old way (No longer supported)
export default defineRoute({
  schema: {
    body: z.object({ title: z.string() })
  },
  handler: async (ctx) => { ... }
});
Enter fullscreen mode Exit fullscreen mode

That was unnecessary nesting. In v2.3.0, you write your checks right at the top level:

// ✅ New way (Cleaner & faster to read)
import { defineRoute, z } from 'bro-framework';

export default defineRoute({
  body: z.object({
    title: z.string()
  }),
  handler: async ({ body }) => {
    return { message: "Saved!", title: body.title };
  }
});
Enter fullscreen mode Exit fullscreen mode

If your code has the old schema wrapper, bro.js catches it on startup and tells you exactly how to update it.

2. Automatic Language Detection

Browsers send a header called Accept-Language that tells the server what languages the user understands, sorted by preference (for example: "I prefer German, but French is okay too").

In v2.3.0, bro.js handles all of this for you:

1. Create a locale/ folder in your project root.

2. Add your language files:

// locale/fr.js
export default {
  welcome: "Bienvenue, {name}!",
  error: "Une erreur est survenue."
};
Enter fullscreen mode Exit fullscreen mode

3. Use the built-in translator directly in your routes:

export default defineRoute({
  handler: async ({ t, locale }) => {
    return {
      message: t('welcome', { name: 'Alex' }),
      userLanguage: locale
    };
  }
});
Enter fullscreen mode Exit fullscreen mode

bro.js checks the client's language list, skips any languages marked with zero preference, and picks the best match you have available.

3. Clearer API Documentation

bro.js automatically builds interactive documentation for your API.

Now, you can also tell your docs what a successful 200 OK response looks like using the new response option:

export default defineRoute({
  response: z.object({
    success: z.boolean(),
    userId: z.string()
  }),
  handler: async () => {
    return { success: true, userId: "123" };
  }
});
Enter fullscreen mode Exit fullscreen mode

This is completely optional. If you just want to return a quick object without defining a schema for it, the framework stays out of your way.

4. Under-the-Hood Improvements

  • Upload Protection: Changing a single upload setting (like maximum file size) keeps all your other safety limits intact.
  • Clean Database Teardown: Added an onShutdown option to bro.config.js so you can close database pools when shutting down.
  • Frontend SDK Polish: Fixed dynamic route naming bugs when using $ in parameters.

Getting Started

Install or upgrade to the latest version:

npm install bro-framework@latest
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.