Plugin Helper: Http Server
Last updated
Was this helpful?
Last updated
Was this helpful?
The http_server
helper creates an HTTP server. This helper was introduced in v1.6.0.
It supports -based server to improve the performance. If async-http
gem is not installed, this helper uses the standard server instead.
Here is an example:
NOTE: The launched plugin itself is managed by its plugin helper which stops it automatically. No need to stop it in the stop
method.
create_http_server(title, addr:, port:, logger:, default_app: nil, &block)
(deprecated)This method is deprecated! Use http_server_create_http_server
method instead.
http_server_create_http_server(title, addr:, port:, logger:, default_app: nil, proto: nil, tls_opts: nil, &block)
It creates and starts an HTTP server with the given routes defined in &block
.
title
: The name of the listening thread. Must be unique!
addr
: The address to listen to.
port
: The port to listen to.
logger
: The logger used in the server helper.
default_app
: The object to handle the requests with unregistered paths. This
object must have a #call
method or must be a Proc
object.
proto
: Protocol type. Supported values: {:tcp
, :tls
} (default: :tcp
)
tls_opts
: TLS options. Same as the Server Helper's
http_server_create_https_server(title, addr:, port:, logger:, default_app: nil, tls_opts: nil, &block)
It creates and starts an HTTPS server with the given routes defined in &block
.
title
: The name of the listening thread. Must be unique!
addr
: The address to listen to.
port
: The port to listen to.
logger
: The logger used in the server helper.
default_app
: The object to handle the requests with unregistered paths. This
object must have a #call
method or must be a Proc
object.
tls_opts
: TLS options. Same as the Server Helper's
Request supports these following methods:
query_string
: returns query string like hoge=v1&fuga=v2
query
: returns query which is query_string
parsed by CGI.parse
body
: returns the request body
path
: returns the request path
The http_server
helper expects an array as the return value i.e.:
${response_status}
should be an Integer
${headers}
should be a Hash
${body}
should be a String
or nil
Here is an example of request and response in JSON format:
http_server
.
.
If this article is incorrect or outdated, or omits critical information, please . is an open-source project under . All components are available under the Apache 2 License.