Class: Spikard::App

Inherits:
Object
  • Object
show all
Defined in:
lib/spikard/service.rb

Overview

Spikard application builder.

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



8
9
10
11
# File 'lib/spikard/service.rb', line 8

def initialize
  # Create a new application with the default server configuration.
  @registrations = []
end

Instance Method Details

#config(config) ⇒ Object



13
14
15
16
17
# File 'lib/spikard/service.rb', line 13

def config(config)
  # Set the server configuration.
  @config = config
  self
end

#connect(path: String, &block) ⇒ Object



77
78
79
80
81
# File 'lib/spikard/service.rb', line 77

def connect(path: String, &block)
  # Register a CONNECT route at the given path.
  @registrations.push(["connect", [spikard::Method::Connect, path], block])
  self
end

#delete(path: String, &block) ⇒ Object



59
60
61
62
63
# File 'lib/spikard/service.rb', line 59

def delete(path: String, &block)
  # Register a DELETE route at the given path.
  @registrations.push(["delete", [spikard::Method::Delete, path], block])
  self
end

#get(path: String, &block) ⇒ Object



35
36
37
38
39
# File 'lib/spikard/service.rb', line 35

def get(path: String, &block)
  # Register a GET route at the given path.
  @registrations.push(["get", [spikard::Method::Get, path], block])
  self
end

#head(path: String, &block) ⇒ Object



65
66
67
68
69
# File 'lib/spikard/service.rb', line 65

def head(path: String, &block)
  # Register a HEAD route at the given path.
  @registrations.push(["head", [spikard::Method::Head, path], block])
  self
end

#into_routerObject



98
99
100
101
102
103
104
105
# File 'lib/spikard/service.rb', line 98

def into_router
  # Build the underlying Axum router.
  #
  # # Errors
  #
  # Returns an error if server or router construction fails.
  Spikard.app_into_router(@registrations)
end

#options(path: String, &block) ⇒ Object



71
72
73
74
75
# File 'lib/spikard/service.rb', line 71

def options(path: String, &block)
  # Register an OPTIONS route at the given path.
  @registrations.push(["options", [spikard::Method::Options, path], block])
  self
end

#patch(path: String, &block) ⇒ Object



53
54
55
56
57
# File 'lib/spikard/service.rb', line 53

def patch(path: String, &block)
  # Register a PATCH route at the given path.
  @registrations.push(["patch", [spikard::Method::Patch, path], block])
  self
end

#post(path: String, &block) ⇒ Object



41
42
43
44
45
# File 'lib/spikard/service.rb', line 41

def post(path: String, &block)
  # Register a POST route at the given path.
  @registrations.push(["post", [spikard::Method::Post, path], block])
  self
end

#put(path: String, &block) ⇒ Object



47
48
49
50
51
# File 'lib/spikard/service.rb', line 47

def put(path: String, &block)
  # Register a PUT route at the given path.
  @registrations.push(["put", [spikard::Method::Put, path], block])
  self
end

#register_route(builder, handler) ⇒ Object



29
30
31
32
33
# File 'lib/spikard/service.rb', line 29

def register_route(builder, handler)
  # Register a route callback directly without block syntax.
  @registrations.push(["route", [builder], handler])
  self
end

#route(builder, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/spikard/service.rb', line 19

def route(builder, &block)
  # Register a route using the provided builder and handler function.
  #
  # # Errors
  #
  # Returns an error if route construction fails or if the handler registration fails.
  @registrations.push(["route", [builder], block])
  self
end

#runObject



89
90
91
92
93
94
95
96
# File 'lib/spikard/service.rb', line 89

def run
  # Run the HTTP server using the configured routes.
  #
  # # Errors
  #
  # Returns an error if server construction or execution fails.
  Spikard.app_run(@registrations)
end

#trace(path: String, &block) ⇒ Object



83
84
85
86
87
# File 'lib/spikard/service.rb', line 83

def trace(path: String, &block)
  # Register a TRACE route at the given path.
  @registrations.push(["trace", [spikard::Method::Trace, path], block])
  self
end