Skip to content

Latest commit

 

History

History
101 lines (76 loc) · 2.11 KB

README.md

File metadata and controls

101 lines (76 loc) · 2.11 KB

ActionHandler

CodeFactor Build Status

Installation

Add this line to your application's Gemfile:

gem 'action_handler', git: 'git://github.com/qcx/action_handler.git', tag: 'v0.2.0'

And then execute:

$ bundle

Usage

# serverless.yml

functions:
  listItems:
    handler: app/handlers/items_handler.ItemsHandler.index
    events:
      - http:
          method: get
          path: items
  showItems:
    handler: app/handlers/items_handler.ItemsHandler.show
    events:
      - http:
          method: get
          path: items/{id}
  updateItems:
    handler: app/handlers/items_handler.ItemsHandler.update
    events:
      - http:
          method: put
          path: items/{id}
# app/handlers/items_handler.rb

class ItemsHandler < ActionHandler::Base
  source ActionHandler::Sources::HTTP.new

  def index
    render json: Item.all
  end

  def show
    render json: Item.find(params[:id])
  end

  def update
    Item.find(params[:id]).update(params)
    render status: 204
  end
end

Params

Parsed from the received event

Supports

  • HTTP
  • SQS
  • SNS
  • S3

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/qcx/action_handler. This project is intended to be a safe, welcoming space for collaboration.

Roadmap

More sources

  • CloudWatch
  • DynamoDB
  • Kinesis

Map status codes

render status: :ok
render status: :no_content

Renderers for each content type

render json: Item.all # should use Renderers::Json.new(args).render

License

The gem is available as open source under the terms of the MIT License.