API Routes

RequestTypeAPI Routes

The INEX SPA framework now supports RequestTypeAPI Routes, a specialized form of API routing optimized for clean and lightweight API responses without loading additional JavaScript resources. This feature is ideal for building APIs and backend services efficiently within your INEX SPA application.


πŸš€ Why Use RequestTypeAPI Routes?

By default, standard route files in INEX SPA load several JavaScript and CSS assets automatically to support frontend functionality. While this is great for full pages, it's unnecessary for API responses, where clean JSON output is expected.

RequestTypeAPI Routes solve this by:

  • Disabling the automatic loading of JS/CSS assets.

  • Returning pure JSON responses.

  • Enhancing performance for frontend consumers (AJAX, Fetch API, mobile apps, etc).


πŸ“‚ File Naming Convention

RequestTypeAPI Route files follow this pattern:

Where:

  • [route] is your route name (e.g., test2).

  • [METHOD] is the HTTP method (GET, POST, etc).

  • The _api suffix distinguishes it from standard RequestType routes.


✨ Creating a RequestTypeAPI Route

You can easily generate a RequestTypeAPI route using the CLI command:

Then follow the prompts:

  1. Enter the route name: test2

  2. Is it dynamic? no

  3. Select request type: GET

  4. Is this an API Route? yes

This will create a file named:


πŸ§‘β€πŸ’» Example Code

Edit the generated file and add the following:


πŸ“Š Response Comparison

πŸ§ͺ Standard RequestType Route:

βœ… RequestTypeAPI Route:


πŸ“˜ Summary

RequestTypeAPI Routes provide a clean, minimal, and efficient way to build APIs inside INEX SPA. They are especially useful for frontend frameworks, mobile apps, and AJAX calls where only the raw data is needed without additional JS dependencies.

Make sure to use the _api suffix in your route file name to activate this mode.


Happy Coding with INEX SPA! ⚑

Last updated