Skip to content

Latest commit

 

History

History
57 lines (43 loc) · 1.37 KB

README.md

File metadata and controls

57 lines (43 loc) · 1.37 KB

crystal-http

Usage

faas-cli template pull https://github.com/koffeinfrei/crystal-http-template
faas-cli new --lang crystal-http function_name

Example

Edit the function_name/handler.rb file to return some HTML:

require "http/request"
require "http/headers"

class Handler
  def run(request : HTTP::Request)
    {
      body:        "<p>Hello, Crystal. You said: #{request.body.try(&.gets_to_end)}</p>",
      status_code: 200,
      headers:     HTTP::Headers{"Content-Type" => "text/html"},
    }
  end
end

Add a shard to the function_name/shard.yml if you need additional dependencies.

Deploy

faas-cli up -f function_name.yml

Specification

The handler needs to return a NamedTuple with the keys body, headers, status_code. At least one of the keys must be present. The following is the type annotation for the return value:

NamedTuple(body: String, headers: HTTP::Headers, status_code: Int32) |
NamedTuple(body: String, headers: HTTP::Headers) |
NamedTuple(body: String, status_code: Int32) |
NamedTuple(body: String) |
NamedTuple(headers: HTTP::Headers, status_code: Int32) |
NamedTuple(headers: HTTP::Headers) |
NamedTuple(status_code: Int32)

Credits

This template is inspired by ruby-http and crystal_openfaas