Jul 18, 2026 tech 13

Eks-Cent Framework

Eks-Cent is a lightweight, modern Ruby web framework that utilizes the Eks Interface standard. It is designed for speed, high-level security, and flexibility, without the burden of heavy external dependencies. With version 4.0.0, Eks-Cent now supports advanced architectural features such as URL Mapping and Application Cascading.

Eksa Framework Logo

Eksa Framework v4.0.0 ๐Ÿš€

Eksa Framework is a modern, lightweight Ruby web framework built upon the Eks Interface standard. It is engineered for speed, high-level security, and flexibility without the bloat of massive external dependencies. With v4.0.0, Eksa Framework now supports advanced architectural features such as URL Mapping and Application Cascading.


โœจ Key Features in v4.0.0

  • ๐Ÿ›ค Modern Routing DSL: Intuitive route definition with dynamic parameters (:name), namespaces, and execution control (halt).
  • ๐Ÿ—บ URL Mapping & Cascading: Run multiple independent applications under a single server based on sub-paths (path mapping) or automatic fallback.
  • ๐Ÿ” Security First: HMAC-SHA256 encrypted sessions, automatic XSS protection, built-in security headers, and parameter limiting (DoS protection).
  • ๐Ÿ›  Standard Middleware Suite:
  • Runtime: Monitor performance with the X-Runtime header.
  • MethodOverride: Use PUT/DELETE from standard HTML forms.
  • Head: Automatic handling of HEAD requests.
  • Session, Logger, Static, ShowExceptions, etc.
  • ๐ŸŽจ Smart Templating: ERB integration with an Auto-Layout system, @req/@res object injection, and secure @h helper for HTML escaping.
  • ๐Ÿงช First-Class Testing: Built-in testing infrastructure using MockRequest and MockResponse.
  • โšก Production Ready: Full integration with Eksa-Server (Cluster mode & Workers) and the ekscentup CLI tool.

๐Ÿš€ Quick Start (v4 Style)

Create a config.eks file to define your application:

# 1. Global Middlewares
use Eksa::Middleware::Runtime
use Eksa::Middleware::MethodOverride
use Eksa::Middleware::Session
use Eksa::Middleware::Logger

# 2. API Application Mapping
map "/api" do
  api = Eksa::Router.new do
    get '/status' do |req, res|
      res.content_type = 'application/json'
      res.write({ status: 'online', version: Eksa::VERSION }.to_json)
    end
  end
  run api
end

# 3. Main Web Application
router = Eksa::Router.new do
  get '/' do |req, res|
    req.session['visits'] ||= 0
    req.session['visits'] += 1
    res.write "<h1>Main Web v#{Eksa::VERSION}</h1>"
    res.write "<p>Your visits: #{req.session['visits']}</p>"
  end
end

run router

Run it using the command:

ekscentup -R --port 3000

๐Ÿ›ค Routing Documentation

Router DSL

You can define routes using standard HTTP methods (get, post, put, delete, patch, options, any).

router = Eksa::Router.new do
  get '/user/:id' do |req, res|
    id = req.params['id']
    res.write "User ID: #{id}"
  end

  namespace '/admin' do
    get '/dashboard' do |req, res|
      # Accessed via /admin/dashboard
    end
  end

  # Execution Control
  get '/secret' do |req, res|
    halt(403, "Access Denied") unless req.session['admin']
    res.write "Secret Data"
  end
end

URL Mapping & Cascade

Use map to split large applications into smaller sub-apps. Use cascade if you want to try multiple applications sequentially until one responds (other than a 404).


๐Ÿ“ฆ Built-in Middleware

Middleware Description
Eksa::Middleware::Runtime Adds an X-Runtime header with execution time.
Eksa::Middleware::MethodOverride Allows overriding HTTP methods via the _method parameter.
Eksa::Middleware::Session Secure, HMAC-based cookie session management.
Eksa::Middleware::Logger Logs requests to STDOUT or a log file.
Eksa::Middleware::Static Serves static files from a specific directory (e.g., public).
Eksa::Middleware::ShowExceptions Displays an informative error page when a crash occurs.
Eksa::Middleware::ContentSecurity Adds standard security headers (X-Content-Type, X-Frame-Options).
Eksa::Middleware::Head Automatically empties the body for HEAD requests.

๐ŸŽจ Templating & Layout

Place your .erb files in the views/ directory. By default, the framework will look for views/layout.erb as the main wrapper.

views/layout.erb:

<html>
  <body>
    <header>My App</header>
    <%= @content %> <!-- Rendered content will be injected here -->
  </body>
</html>

Within the Router:

res.render 'index', title: "Hello World"

Context Injection: The @req (request) and @res (response) objects, as well as the @h helper (HTML escape), are always available within templates.


๐Ÿ›  API Guide (Request & Response)

Eksa::Request (req)

  • req.params: Retrieve query, POST, or route parameters.
  • req.session: Access session data (Read/Write).
  • req.request_method: Get the HTTP method (GET, POST, etc.).
  • req.path: Get the current URL path.
  • req.user_agent: Get browser information.

Eksa::Response (res)

  • res.write(string): Append content to the response body.
  • res.set_header(key, value): Set an HTTP header.
  • res.content_type = 'type': Shortcut to set Content-Type.
  • res.status = code: Set status code (default: 200).
  • res.redirect(path): Perform a URL redirect.
  • res.render(template, locals): Render an ERB template.

๐Ÿงช Testing

Use the built-in testing suite to ensure your application behaves correctly:

require 'test/unit'
require 'eksa'

class MyAppTest < Test::Unit::TestCase
  def test_homepage
    app = Eksa.load('config.eks')
    mock = Eksa::MockRequest.new(app)

    res = mock.get('/')
    assert res.ok?
    assert_match "Welcome", res.body_content
  end
end

๐Ÿ›ก Security Limits (Eks Limits)

You can set limits on parameter parsing via environment variables to prevent DoS attacks:

  • EKS_QUERY_PARSER_PARAMS_LIMIT: Maximum number of parameters (default: 1000).
  • EKS_QUERY_PARSER_DEPTH_LIMIT: Maximum nested parameter depth.
  • EKS_MULTIPART_TOTAL_PART_LIMIT: Maximum parts in a multipart form.

๐Ÿ“„ License

Eksa Framework v4.0.0 is published under the MIT License.

13 views

RELATED POSTS

COMMENTS (0)

Leave a Comment