simple_service_api

Unified Service Layer for Eiffel Web Applications

Service Layer v1.0.0 MIT

Overview

simple_service_api bundles all web application services into one SERVICE class. Inherits from FOUNDATION, giving you core utilities as well.

What You Get

JWT Auth

Create and verify JSON Web Tokens

SQL Database

SQLite with file or in-memory storage

SMTP Email

Send emails via SMTP with TLS

CORS

Cross-Origin Resource Sharing

Rate Limiting

Protect APIs from abuse

Templates

Render with {{variable}} substitution

WebSocket

Handshake, frames, protocol support

Base64/Hash

Encoding, MD5, SHA (inherited)

JSON/CSV

Parse and generate (inherited)

Installation

<library name="simple_service_api"
        location="$SIMPLE_SERVICE_API\simple_service_api.ecf"/>

Quick Start

local
    service: SERVICE
do
    create service.make

    -- JWT Authentication
    token := service.create_token ("secret", "user@example.com", "my-app", 3600)
    if service.verify_token ("secret", token) then
        print ("Valid!%N")
    end

    -- Database
    db := service.new_memory_database
    db.execute ("CREATE TABLE users (id INTEGER PRIMARY KEY)")

    -- Rate Limiting
    limiter := service.new_rate_limiter (100, 60)

    -- Foundation (inherited)
    hash := service.sha256 ("password")
end

API Reference

JWT Authentication

new_jwt (secret): SIMPLE_JWT
create_token (secret, subject, issuer, expires): STRING
verify_token (secret, token): BOOLEAN

SQL Database

new_database (path): SIMPLE_SQL
new_memory_database: SIMPLE_SQL

SMTP Email

new_smtp (host, port): SIMPLE_SMTP

CORS

new_cors: SIMPLE_CORS
new_cors_permissive: SIMPLE_CORS

Rate Limiting

new_rate_limiter (max_requests, window_seconds): SIMPLE_RATE_LIMITER

Templates

new_template: SIMPLE_TEMPLATE
render_template (template, data): STRING

WebSocket

new_ws_handshake: WS_HANDSHAKE
new_ws_frame_parser: WS_FRAME_PARSER
new_ws_text_frame (text, is_final): WS_FRAME
new_ws_binary_frame (data, is_final): WS_FRAME
new_ws_close_frame (code, reason): WS_FRAME

Foundation (inherited)

base64_encode (data): STRING
base64_decode (data): STRING
md5 (data): STRING
sha256 (data): STRING
new_uuid: STRING
parse_json (text): SIMPLE_JSON_VALUE

Bundled Libraries

Library Purpose
simple_jwtJWT authentication
simple_sqlSQLite database
simple_smtpEmail sending
simple_corsCORS handling
simple_rate_limiterRate limiting
simple_templateTemplate rendering
simple_websocketWebSocket protocol
simple_foundation_apiCore utilities (inherited)