Global Prefix, Raw Body & Hybrid Apps
Global Prefix, Raw Body & Hybrid Apps
Production APIs often need platform-level HTTP choices that affect every route: a global /api prefix, URI or header versioning, raw request bodies for webhook signatures, HTTPS options, or a hybrid HTTP plus microservice application.
Core idea
This feature is about controlling how the application is organized and how it behaves at runtime. These are the points a developer should understand before using it in a real project:
- setGlobalPrefix() keeps API routes grouped and lets static or frontend routes live beside them.
- enableVersioning() supports URI, header, media type, or custom version extraction strategies.
- Raw body support must be enabled before body parsing when validating Stripe, GitHub, or payment-provider signatures.
- connectMicroservice() attaches a microservice server to the same Nest application context.
- HTTPS and multiple servers can be configured at bootstrap, but a reverse proxy is often cleaner in production.
Practical example
The following example shows the idea in a practical NestJS project. The goal is not to memorize the snippet, but to understand where it belongs in the architecture:
Production checklist
- Document global prefixes and versioning in OpenAPI.
- Exclude health checks from auth and global prefixes only when infrastructure requires it.
- Test raw body signatures before enabling global validation or body transforms.
- Keep hybrid app lifecycle in one bootstrap function so shutdown behavior is predictable.
Summary
This lesson covers an advanced NestJS area that matters when building enterprise applications. Focus on clear boundaries, testable behavior, and choosing the right tool for the context instead of using every feature everywhere.