Coder Social home page Coder Social logo

cylon-v / dandy Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 150 KB

Dandy is a cutting-edge ruby framework for developing web-applications

License: MIT License

Ruby 99.88% Shell 0.12%
ruby rack web-framework dependency-injection dandy atomic-actions

dandy's Introduction

Dandy Build Status

Dandy is a minimalistic web API framework. Its main idea is to implement an approach from Clean Architecture principles - "web is just a delivery mechanism". Dandy is build on top of IoC container Hypo and forces to use dependency injection approach everywhere.

Basic Concepts

  1. Dependency Injection is a heart of Dandy. Atomic actions can depend on request parameters, services, repositories, output of other actions and other stuff. You can easily inject such dependencies in your actions through a constructor. Dependency Injection significantly improves development experience: isolate your components, enjoy writing unit tests.
class LoadPost
  def initialize(id, post_storage)
    @id = id
    @storage = post_storage
  end
  
  def call
    @storage.find(@id)
  end
end
  1. Instead of boring Ruby block-style routes definition like in Rails, Sinatra and others Dandy uses its own language for that. Small example:
:receive
    .->
        :before -> user@load_current_user          
        /posts ->
            $id ->
                :before -> load_post
                /comments ->
                    POST -> add_comment -> notify_author \
                         -> notify_subscribers -> :respond <- comment_test =201
:catch -> handle_errors
  1. The combination of flexible router and dependency injection breaks existing dogmas. Dandy framework introduces Abstract Chain pattern as a replacement for Model-View-Controller and other ancient approaches. Every request handles by a set of atomic actions.
    # POST /posts/$id/comments
    ... -> load_post -> add_comment -> ... 
class LoadPost
  def initialize(id, post_storage)
    @id = id
    @storage = post_storage
  end
  
  def call
    @storage.find(@id)
  end
  
  def result_name
    'post'
  end 
end

class AddComment
  def initialize(post, dandy_data, user, comment_storage)
    @post = post
    @data = dandy_data
    @user = user
    @storage = comment_storage 
  end
  
  def call
    @storage.create(post: @post, message: @data[:message], user: @user)
  end  
end
  1. Dandy is a micro-framework for micro-services. It's not intended to create monolithic giants! In terms of Domain Driven Design concepts one Dandy application should wrap only one Bounded Context.

Getting Started

  1. Install Dandy:
    $ gem install dandy
  1. At the command prompt, create a new Dandy application:
    $ dandy new dandy-app
  1. Go to directory dandy-app and start the application using a server you prefer:
    $ puma -p 8000 config.ru

or just

    $ rackup -p 8000 config.ru
  1. Run curl command curl http://localhost:8000 -H "Accept: application/json" and you'll see:
  {"message": "Welcome to dandy-app!"}

Please take attention - HTTP header "Accept: application/json" is a mandatory.

  1. Investigate example application code, it explains most of Dandy aspects.
  2. For more details visit our Wiki.

Development

Usual, but always helpful steps:

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cylon-v/dandy.

License

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

dandy's People

Contributors

cylon-v avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dandy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.