C/C++ Server Pages for Embedded Devices

One of the options for developing server-side generated web pages is to use what we refer to as C Server Pages (CSP). CSP is designed for dynamically generating HTML on the server, making it similar to technologies like JSP, PHP, and ASP.

CSP allows embedding C or C++ code directly in HTML template files using special CSP tags. The Barracuda Embedded Web Server SDK provides host tools that process these CSP files, converting them into C or C++ code, which is then compiled and linked with your application. This enables efficient generation of dynamic content within HTML pages.

However, CSP is typically not used to handle AJAX and REST requests. The Barracuda Embedded Web Server provides a far more efficient and streamlined approach, allowing you to quickly implement RESTful APIs and AJAX endpoints directly in C and C++. The server can handle REST requests with minimal overhead by leveraging the built-in directory object.

CSP Page Counter Example:

<%! int count; %>

<%!! count = 1; %>

<html>
  <body>
    <p>
      You are visitor <%="%d" count++%>.
    </p>
  </body>
</html>


CSP is great, but using C during the development process incurs some overhead as shown in the figure below.

Choosing the Best Device Management Framework

In modern web development, iterative testing during development is essential. However, compiling C code for every change can slow down the process and add unnecessary complexity. That's where Lua Server Pages (LSP) comes in a rapid development framework designed to streamline web application development.

With LSP, you gain significant advantages:

  • Faster development - No need for compilation; make changes and see results instantly.
  • Easier maintenance - Readable, high-level scripting reduces complexity and improves code manageability.
  • Safer code - Avoid common pitfalls of low-level memory management in C.
  • Effortless RESTful and AJAX integration - LSP makes handling RESTful APIs and AJAX requests incredibly simple, requiring minimal, compact code while leveraging Lua’s flexibility.

If you're considering building your project purely in C, it's worth exploring the efficiency and flexibility of combining C with a high-level scripting language like Lua. This approach makes development faster, more maintainable, and safer, particularly for modern web-based device management applications .

Before deciding on C only, check out the following:

Refer to our online CSP documentation for a detailed introduction to C Server Pages.


Next: Why Use Lua