Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a block normally #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,13 @@ targets:
require "json"
require "crambda"

def handler(event : JSON::Any, context : Crambda::Context)
Crambda.run_handler do |event, context|
pp context
JSON.parse("[1, 2]")
end

Crambda.run_handler(->handler(JSON::Any, Crambda::Context))
```

Where `Crambda.run_handler` expects a handler that takes a `JSON::Any` event
and a `Context`, and returns a `JSON::Any` response:

```crystal
def self.run_handler(handler : Proc(JSON::Any, Context, JSON::Any))
# ...
[1, 2]
end
```

And `Context` is a class that looks like this:
`Crambda.run_handler` expects a block that takes a `JSON::Any` event and a `Crambda::Context` and returns an object that implements `to_json`. The `Crambda::Context` is a class that looks like this:

```crystal
class Context
Expand Down
4 changes: 4 additions & 0 deletions src/crambda.cr
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ module Crambda
end
end
end

def self.run_handler(&block : JSON::Any, Context -> T) forall T
run_handler block
end
end