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

Introduce Hanami::API::DSL #20

Merged
merged 2 commits into from
Nov 12, 2020
Merged

Introduce Hanami::API::DSL #20

merged 2 commits into from
Nov 12, 2020

Conversation

jodosha
Copy link
Member

@jodosha jodosha commented Oct 22, 2020

Feature

Introduce Hanami::API::DSL which gives the ability to other frameworks to use the Hanami::API DSL.

Example

Imagine you're building a web framework, or simply you need a routing DSL. You declare a superclass like this:

# framework.rb
require "hanami/api"

module Framework
  class App
    def self.inherited(base)
      super
      base.extend(Hanami::API::DSL)
    end
  end
end

Then in your app, you inherit from your superclass, which has now a .routes class method that can wrap all the routes. Within that block you have all the Hanami::API methods available.

 # app.rb
require "framework/app"

class MyApp < Framework::App
  routes do
    root { "Hello, World!" }
  end
end

In config.ru (for Rack web servers), you just initialize your app.

# config.ru
require_relative "./app"

run MyApp.new

@jodosha jodosha self-assigned this Oct 22, 2020
@timriley
Copy link
Member

@jodosha This is great!

@jodosha jodosha merged commit 3c66eb0 into master Nov 12, 2020
@jodosha jodosha deleted the task/hanami-api-dsl branch November 12, 2020 08:24
@jodosha jodosha added this to the v0.2.0 milestone Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants