• This repository has been archived on 13/Sep/2020
  • Stars
    star
    20
  • Rank 1,086,145 (Top 22 %)
  • Language
    Crystal
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Action-focused HTTP routing library for Crystal

Beryl

Build Status

Action-focused HTTP routing library for Crystal

Description

Beryl aims to be a small HTTP routing library with focus on direct mapping between route paths and their respective actions.

Both Router and Action design give certain flexibility for testing each component individually.

It leverages on Crystal's HTTP library and allows you to integrate it with other middleware to build your final stack.

Installation

Add it to your project's shard.yml file:

dependencies:
  beryl:
    github: luislavena/beryl

Usage

The following example presents a simpler Router that maps the root element of a request (/) to a specific Action.

class Hello < Beryl::Action
  def call(params)
    HTTP::Response.ok "text/plain", "Hello world!"
  end
end

class App < Beryl::Router
  routing do
    get "/", Hello
  end
end

We assume you understand how to use HTTP::Server and are comfortable with using and building HTTP::Request and HTTP::Response respectively.

You can now place an instance of App on your HTTP middleware or be the single one handler in your stack:

server = HTTP::Server.new(8080, App.new)
server.listen

Or combine with others:

stack = [
  HTTP::LogHandler.new,
  App.new
]

server = HTTP::Server.new(8080, stack)
server.listen

You can see other examples in the samples/ directory.

Radix Tree implementation

This project implement a Radix tree to perform route matching.

This has been inspired and adapted from julienschmidt/httprouter and spriet2000/vertx-http-router Go and Java implementations, respectively.

Changes to logic and optimizations have been made to take advantage of Crystal's features.

Development

  • HTTP Handler integration
  • Path/Query parameter extraction
  • Router/Route/Action initial design
  • Nested routers (ie. resource specific mappings)
  • Optional Response helpers for Action (eg. html, json)
  • Optional conditional rendering (eg. stale, etag, last_modified)

Contributing

  1. Fork it ( https://github.com/luislavena/crystal-beryl/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

More Repositories

1

bench-micro

Benchmark some Ruby web microframeworks, just for fun
Ruby
240
star
2

gem-compiler

A RubyGems plugin that generates binary gems
Ruby
154
star
3

radix

Radix Tree implementation for Crystal
Crystal
101
star
4

mysql-gem

MySQL/Ruby Bindings, wrapped as Gem with improved cross-platform support
C
52
star
5

brooklyn

Brooklyn - Small web tool on top of Rack
Ruby
23
star
6

win32console

DEPRECATED: Mirror of Win32::Console Gem project with improved MinGW support
Ruby
22
star
7

service_wrapper

Wrap any command-line tool as Windows service (WiP)
Visual Basic
21
star
8

mongrel_service

Mongrel::Service
Visual Basic
12
star
9

binfiles

Personal scripts Tools
Visual Basic
11
star
10

homelab-headscale

Making it easy (for me) to deploy a production-ready Headscale setup to Fly.io
Shell
10
star
11

hydrofoil-crystal

Opinionated, Alpine-based development container for Crystal
Dockerfile
10
star
12

crystal-state_machine

State Machine for Crystal
Crystal
9
star
13

fenix

OBSOLETE: Rebirth and renewal of Ruby (see README)
Ruby
6
star
14

test-ruby-c-extension

Test ground of rake-compiler extension compilation. Useful for reporting bugs during cross-compilation issues
Ruby
6
star
15

template-laravel-twill

An empty Laravel + Twill project template using Docker and Docker compose for local development
PHP
6
star
16

nekro

Ruby to Neko (playground)
Ruby
5
star
17

magic-haversack

Facilitate Crystal cross-compilation
Shell
5
star
18

learn-chef

Explore ideas and try to understand how Chef works
Ruby
4
star
19

testly

Testly is a simple, minimal testing library aimed to programmers using FreeBASIC to implement TDD development techniques
Visual Basic
4
star
20

simple_logger

SimpleLogger is a simple, minimal logger library for programmers using FreeBASIC inspired in ruby logger or log4cpp.
4
star
21

learn-ansible

Explore some playbooks organization with Ansible
Shell
4
star
22

exp-crystal-hello-binary

๐Ÿงช Compile and package static binaries with Crystal
Crystal
4
star
23

drift

SQL-driven schema migration tool and library for Crystal
Crystal
4
star
24

isolate-lockdown

Lockdown your isolated gems, give them speed.
Ruby
3
star
25

hydrofoil-php

Opinionated, PHP environment tailored for development
Dockerfile
3
star
26

simple-bench-ruby-io

Provide a simple test ground to benchmark Ruby require bottlenecks
Ruby
2
star
27

sinatra-hello

Testing Cloud deployment with Sinatra
Ruby
2
star
28

experiments

Place to put all those little experiments that are too small for their own repository.
C
2
star
29

servicefb

ServiceFB simplify programmers work when creating NT Services using FreeBASIC as programming language. It also encapsulate most of the Win32 API and provide a clean event-driven like interface.
2
star
30

autotest-snarl

Clean and stolen easy integration of Net::Snarl and autotest
Ruby
1
star
31

autobuild-rubies

Automated Ruby builds using Travis-CI
Shell
1
star
32

test-crystal-cross-compiling

A container image that combines Zig toolchain and packages for different platforms to facilitate compiling Crystal apps
Dockerfile
1
star
33

test-unicode

Sample files for testing unicode capabilities of Windows consoles
Ruby
1
star
34

mini_service

Create Windows Services, and just that
Ruby
1
star
35

net-snarl

Basic Snarl SNP implementation in Ruby
Ruby
1
star
36

test-crystal-sqlite3-db

Repo showcasing multi-thread issues with crystal-sqlite3 (crystal-lang/crystal-sqlite3#87)
Crystal
1
star
37

dockerfiles

Experimental Docker containers for development (DEPRECATED)
Shell
1
star
38

greek-steam

Debian-based PHP container image for production usage, tailored for Laravel Vapor & Twill CMS
Dockerfile
1
star