onyx-http

REST API framework with type-safe params and separate business and rendering layers, based on onyx-http web framework router websockets modular http-handler onyxframework
0.9.0 Latest release Yanked release released

Onyx::HTTP

Built with Crystal Travis CI build Docs API docs Latest release

An opinionated framework for scalable web.

About πŸ‘‹

Onyx::HTTP is an opinionated HTTP framework for Crystal language. It features DSL and modules to build modern, scalabale web applications with first-class support for websockets.

Installation πŸ“₯

Add these lines to your application's shard.yml:

dependencies:
  onyx:
    github: onyxframework/onyx
    version: ~> 0.6.0
  onyx-http:
    github: onyxframework/http
    version: ~> 0.9.0

This shard follows Semantic Versioning v2.0.0, so check releases and change the version accordingly.

Note that until Crystal is officially released, this shard would be in beta state (0.*.*), with every minor release considered breaking. For example, 0.1.0 β†’ 0.2.0 is breaking and 0.1.0 β†’ 0.1.1 is not.

Usage πŸ’»

The simplest hello world:

require "onyx/http"

Onyx::HTTP.get "/" do |env|
  env.response << "Hello, world!"
end

Onyx::HTTP.listen

Encapsulated endpoints:

struct GetUser
  include Onyx::HTTP::Endpoint

  params do
    path do
      type id : Int32
    end
  end

  errors do
    type UserNotFound(404)
  end

  def call
    user = Onyx::SQL.query(User.where(id: params.path.id)).first? # This code is part of onyx/sql
    raise UserNotFound.new unless user

    return UserView.new(user)
  end
end

Onyx::HTTP.get "/users/:id", GetUser

Encapsulated views:

struct UserView
  include Onyx::HTTP::View

  def initialize(@user : User)
  end

  json id: @user.id, name: @user.name
end

Websocket channels:

struct Echo
  include Onyx::HTTP::Channel

  def on_message(message)
    socket.send(message)
  end
end

Onyx::HTTP.ws "/", Echo

Documentation πŸ“š

The documentation is available online at docs.onyxframework.org/http.

Community πŸͺ

There are multiple places to talk about Onyx:

Support ❀️

This shard is maintained by me, Vlad Faust, a passionate developer with years of programming and product experience. I love creating Open-Source and I want to be able to work full-time on Open-Source projects.

I will do my best to answer your questions in the free communication channels above, but if you want prioritized support, then please consider becoming my patron. Your issues will be labeled with your patronage status, and if you have a sponsor tier, then you and your team be able to communicate with me privately in Twist. There are other perks to consider, so please, don't hesistate to check my Patreon page:

You could also help me a lot if you leave a star to this GitHub repository and spread the word about Crystal and Onyx! πŸ“£

Contributing

  1. Fork it ( https://github.com/onyxframework/http/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'feat: some feature') using Angular style commits
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Licensing

This software is licensed under MIT License.

Open Source Initiative

onyx-http:
  github: onyxframework/http
  version: ~> 0.9.0
License MIT
Crystal 0.30.1

Authors

Dependencies 6

  • callbacks ~> 0.2.0
    {'github' => 'vladfaust/callbacks.cr', 'version' => '~> 0.2.0'}
  • exception_page ~> 0.1.0
    {'github' => 'crystal-loot/exception_page', 'version' => '~> 0.1.0'}
  • http-params-serializable ~> 0.4.0
    {'github' => 'vladfaust/http-params-serializable', 'version' => '~> 0.4.0'}
  • kilt
    {'github' => 'jeromegn/kilt', 'verstion' => '~> 0.4.0'}
  • radix ~> 0.3.0
    {'github' => 'luislavena/radix', 'version' => '~> 0.3.0'}
  • time_format ~> 0.1.0
    {'github' => 'vladfaust/time_format.cr', 'version' => '~> 0.1.0'}

Development Dependencies 0

Dependents 2

Last synced .
search fire star recently