Hana

Hana :: # (opaque)
text : Str -> Try(Response, e)

Return a plain text response with status code 200: OK from a route handler.

The content-type header will be set to text/plain; charset=utf-8.

text_response : U16, Str -> Response

Create a plain text response with the given status code.

The content-type header will be set to text/plain; charset=utf-8.

html : Str -> Try(Response, e)

Return an HTML response with status code 200: OK from a route handler.

The content-type header will be set to text/html; charset=utf-8.

html_response : U16, Str -> Response

Create an HTML response with the given status code.

The body is not validated or escaped. The content-type header will be set to text/html; charset=utf-8.

json : Str -> Try(Response, e)

Return a JSON response with status code 200: OK from a route handler.

The content-type header will be set to application/json; charset=utf-8.

json_response : U16, Str -> Response

Create a JSON response with the given status code.

The body is not validated or encoded. The content-type header will be set to application/json; charset=utf-8.

ok : Response

Create a plain text response with status code 200: OK.

created : Response

Create a plain text response with status code 201: Created.

accepted : Response

Create a plain text response with status code 202: Accepted.

no_content : Response

Create an empty response with status code 204: No content.

redirect : Str -> Response

Create a plain text response with status code 303: See other.

permanent_redirect : Str -> Response

Create a plain text response with status code 308: Permanent redirect.

bad_request : Response

Create a plain text response with status code 400: Bad request.

not_found : Response

Create a plain text response with status code 404: Not found.

content_too_large : Response

Create a plain text response with status code 413: Content too large.

unsupported_media_type : List(Str) -> Response

Create a response with status code 415: Unsupported media type.

The accept header will list the supported media types.

unprocessable_content : Response

Create a plain text response with status code 422: Unprocessable content.

internal_server_error : Response

Create a plain text response with status code 500: Internal server error.

not_implemented : Response

Create a plain text response with status code 501: Not implemented.

halt : Response -> Try(ok, [Halt(Response), ..])

End the current handler with an intentional HTTP response.

This is pure control flow. It does not stop the server.

path : request -> Try(List(Str), [Halt(Response), ..])
    where [
        request.target : request -> [
            Asterisk,
            Authority(authority),
            Resource({ .., raw_path : Str }),
        ],
    ]
path_segments : Str -> List(Str)

Return the segments of an absolute raw URI path.

One leading and one trailing slash are ignored. Internal empty segments remain significant.

routing_method : Method -> Method

Convert a HEAD request method to GET.

This allows an application to handle HEAD requests using its GET handlers.

method_not_allowed : List(Method) -> Response

Create a response with status code 405: Method not allowed.

Use this when a request does not have an appropriate method to be handled. The allow header will be set to a comma-separated list of the permitted methods.

require_method : a, List(
    Method,
) -> Try(
    {  },
    [
        Halt(
            Response,
        ),
        ..,
    ],
)
    where [
        a.method : a -> Method,
    ]

Ensure that a request has one of the permitted HTTP methods.

HEAD requests are checked as GET requests. If the method is not permitted, the handler ends with status code 405: Method not allowed.

resolve : Try(Response, e), (e -> Response) -> Response

Resolve a handler result into a response using the application's error handler.

dev_log! : a, b, (Str -> Try(
    {  },
    err,
)) -> a
    where [
        a.status : a -> b,
        b.method : a -> Method,
        b.target : a -> [
            Asterisk,
            Authority(
                b,
            ),
            Resource(
                {
                    raw_path : Str,
                    ..c,
                },
            ),
        ],
    ]

Write a compact development log line and preserve the response.

Pass a platform writer such as Stderr.line!. Writer errors are ignored so logging cannot change the response. Use the server's access logger when transport completion, byte counts, or production logging are required.

Route

:= [Response(Response), EventStream(stream)]

Opt-in composition for handlers that return ordinary responses and event streams. Response-only applications do not need this type.

response : Try(Response, e) -> Try(Route(stream), e)

Adapt an ordinary response handler result for a mixed route.

event_stream : Try(stream, e) -> Try(Route(stream), e)

Adapt an event stream handler result for a mixed route.

resolve : Try(Route(stream), e), (e -> Response) -> Route(stream)

Resolve a mixed handler result using an ordinary HTTP error response.

map_response : Route(stream), (Response -> Response) -> Route(stream)

Transform an ordinary response while preserving an event stream.

dev_log! : Route(
    stream,
), a, (Str -> Try(
    {  },
    err,
)) -> Route(
    stream,
)
    where [
        a.method : a -> Method,
        a.target : a -> [
            Asterisk,
            Authority(
                b,
            ),
            Resource(
                {
                    raw_path : Str,
                    ..c,
                },
            ),
        ],
    ]

Write a compact development log line and preserve the mixed route.

Event streams are logged as selected, not when their transport finishes.

fold : Route(stream), (Response -> result), (stream -> result) -> result

Fold an ordinary response or event stream into one value.

to_outcome : Route(stream), (Response -> outcome), (stream -> outcome) -> outcome

Convert a mixed route using the platform's outcome constructors.