Lather.Server.Handler (lather v1.1.0)

Copy Markdown View Source

Generic HTTP handler for SOAP server endpoints.

This module provides SOAP server functionality without requiring Plug. It can be used with any HTTP server (Phoenix, Bandit, Cowboy, etc.).

Usage

In Phoenix controller:

defmodule MyAppWeb.SOAPController do
  use MyAppWeb, :controller

  def handle_soap(conn, _params) do
    case Lather.Server.Handler.handle_request(conn.method, conn.request_path, conn.req_headers, conn.assigns.raw_body, MyApp.UserService) do
      {:ok, status, headers, body} ->
        conn
        |> put_status(status)
        |> put_headers(headers)
        |> text(body)
      {:error, status, headers, body} ->
        conn
        |> put_status(status)
        |> put_headers(headers)
        |> text(body)
    end
  end
end

With any HTTP server:

body = read_request_body(request)
headers = get_request_headers(request)

case Lather.Server.Handler.handle_request("POST", "/soap", headers, body, MyApp.UserService) do
  {:ok, status, response_headers, response_body} ->
    send_response(status, response_headers, response_body)
  {:error, status, response_headers, response_body} ->
    send_response(status, response_headers, response_body)
end

Summary

Functions

handle_request(method, path, headers, body, service, opts \\ [])

Handles a SOAP HTTP request.

Returns {:ok, status, headers, body} or {:error, status, headers, body}.

Options

  • :validate_params - Enable parameter validation (default: true)
  • :generate_wsdl - Enable WSDL generation (default: true)
  • :base_url - Base URL for WSDL generation (default: "http://localhost:4000")
  • :max_body_size - Maximum request body size in bytes (default: 10MB). Bodies exceeding this limit are rejected with HTTP 413.

Any GET serves the WSDL (when :generate_wsdl is enabled) and any POST is treated as a SOAP call, regardless of path — matching Lather.Server.Plug. Other methods get a 405 fault.