grip

An object-oriented framework based on Kemal with additional goodness
0.27.1 Yanked release released
grkek/grip
26 1

This repo seems to be no longer available at grkek/grip.

Git synchronization failed . Last successful sync was .

Help find it again! … or have it archived.

Grip

Grip

Class oriented fork of the Kemal framework based on a JSON request/response model with a CRUDish look.

Currently Grip is headed towards a JSON request/response type interface, which makes this framework non-HTML friendly, it is still possible to render HTML but it is not advised to use Grip for that purpose.

So far at 158,762 requests/second, and still going.

Build Status

Super Simple ⚡️

require "grip"
require "uuid" # Needed for the random UUID generation

class IndexHttpConsumer < Grip::HttpConsumer
  def get(req)
    res(
      {
        "id": "#{UUID.random}"
      },
      HTTP::Status::OK # The status code is a mix of a built-in and an integer,
      # By default every res has a 200 OK status response.
    )
  end

  def post(req)
    res(
      {
        "id": "#{UUID.random}"
      }
    )
  end

  def put(req)
    res(
      {
        "id": "#{UUID.random}"
      }
    )
  end

  def delete(req)
    res(
      {
        "id": "#{UUID.random}"
      }
    )
  end
end


class ExcludeHttpConsumer < Grip::HttpConsumer
  def get(req)
    res(
      {
        "id": "#{UUID.random}"
      },
      HTTP::Status::OK # The status code is a mix of a built-in and an integer,
      # By default every res has a 200 OK status response.
    )
  end

  def post(req)
    res(
      {
        "id": "#{UUID.random}"
      }
    )
  end

  def put(req)
    res(
      {
        "id": "#{UUID.random}"
      }
    )
  end

  def delete(req)
    res(
      {
        "id": "#{UUID.random}"
      }
    )
  end
end

class IndexedHttpConsumer < Grip::HttpConsumer
  def index(req)
    puts url # This gets the hash instance of the route url specified variables
    puts query # This gets the query parameters passed in with the url
    puts json # This gets the JSON data which was passed into the route
    puts headers # This gets the http headers

    res(
      {
        "id": "#{UUID.random}"
      }
    )
  end

  def create(req)
    puts url # This gets the hash instance of the route url specified variables
    puts query # This gets the query parameters passed in with the url
    puts json # This gets the JSON data which was passed into the route
    puts headers # This gets the http headers

    res(
      {
        "id": "#{UUID.random}"
      }
    )
  end
end

class EchoWebSocketConsumer < Grip::WebSocketConsumer
  def on_message(req, message)
    puts url # This gets the hash instance of the route url specified variables
    puts headers # This gets the http headers

    if message == "close"
      close "Received a 'close' message, closing the connection!" # This closes the connection
    end

    send message
  end

  def on_close(req, message)
    puts message
  end
end

# Routing
get "/:id", IndexedHttpConsumer, :index
post "/:id", IndexedHttpConsumer, :create

resource "/", IndexHttpConsumer, only: [:get, :post, :put, :delete]
resource "/exclude", ExcludeHttpConsumer, exclude: [:get, :post]

logging true
# Run the server
Grip.run

The default port of the application is 3000, you can set it by either compiling it and providing a -p flag or by changing it from the source code.

Start your application!

If you want logging to show up in the stdout put this line right above the Grip.run in your source code.

logging true # Keep in mind that logging slows down the server since it is an IO bound operation

Installation

Add this to your application's shard.yml:

dependencies:
  grip:
    github: grkek/grip

Features

  • Support all REST verbs
  • Websocket support
  • Request/Response context, easy parameter handling
  • Middleware support
  • Built-in JSON support

Documentation

  • For the framework development just use the crystal docs feature and browse through the module.
  • Check out the official documentation available here

Thanks

Thanks to Manas for their awesome work on Frank.

Thanks to Serdar for the awesome work on Kemal.

Thanks to the official gitter chat of the Crystal programming language.

grip:
  github: grkek/grip
  version: ~> 0.27.1
License MIT
Crystal 0.32.0

Authors

Dependencies 1

  • radix
    {'github' => 'luislavena/radix'}

Development Dependencies 1

  • ameba ~> 0.10.0
    {'github' => 'crystal-ameba/ameba', 'version' => '~> 0.10.0'}

Dependents 0

Last synced .
search fire star recently