Skip to content

koffeinfrei/crystal-http-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

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

About

A Crystal HTTP template for OpenFaaS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published