Trongate Website Homepage

Custom Headers in Trongate MX

The mx-headers attribute in Trongate MX allows you to specify custom headers for your HTTP requests. This feature provides flexibility in managing request headers, which can be useful for tasks such as content negotiation, custom server behaviors, and more.

Syntax

<element mx-headers='{
    "Header-Name": "Header-Value",
    "Another-Header": "Another-Value"
}'></element>

The mx-headers attribute should contain a JSON object, where each key-value pair represents a header and its value.

Usage

To use the mx-headers attribute:

  1. Add the attribute to an element that triggers an AJAX request (e.g., a button with mx-get or mx-post).
  2. Specify the headers in a JSON object format.

Example

<button mx-get="api/resource" 
        mx-headers='{
            "Client-ID": "12345",
            "App-Version": "1.0"
        }'>
    Fetch Resource
</button>

In this example:

Best Practices

  1. Content Negotiation: Use headers like Accept and Content-Type to specify preferred content types and formats.
  2. Custom Behaviors: Implement custom headers to trigger specific behaviors on your server or for tracking purposes.
  3. Modularity: Define reusable headers in a consistent format to maintain clarity and modularity in your code.

Additional Information

  • The mx-headers attribute should contain a valid JSON object. Each key-value pair represents a header and its value.
  • Ensure that the JSON string is properly formatted to avoid parsing errors.
  • The headers specified in mx-headers will be added to the HTTP request along with any default headers set by Trongate MX.

Additional Notes

By utilizing the mx-headers attribute, you can enhance the flexibility and control of your HTTP requests in Trongate MX, making it easier to manage custom headers and improve the robustness of your web applications.