Skip to content
项目

关于

The microframework for writing powerful web applications.

网站与应用开发

这些数字如何统计

可以做什么

  • HTTP 1.1 support.
  • WebSocket RFC 6455 support.
  • Built-in exceptions support.
  • Parameter handling support.

实测星标增长

24小时
0
7天
0
15天
+1
1个月
+1

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

The microframework for writing powerful web applications.

Actions Status

TechEmpower Benchmark

Docs CI Status

Chat on Gitter

Grip is a microframework for building RESTful web applications. It is designed to be modular and easy to use, with the ability to scale up to the limits of the Crystal programming language. It offers extensibility and has integrated middleware called "pipes". Pipes can alter parts of the request/response context and then get passed to the actual endpoint. Grip's router is very similar to the router of the Phoenix framework. And most of all: Grip is fast.

Motivation

This project exists due to the fact that Kemal lacks one crucial part of a framework, a structure. An example for the absence of a structure can be found here.

Features

  • HTTP 1.1 support.
  • WebSocket RFC 6455 support.
  • Built-in exceptions support.
  • Parameter handling support.
  • JSON serialization and deserialization support (fastest framework with JSON in Crystal).
  • Middleware support.
  • Request/Response context, inspired by expressjs.
  • Advanced routing support.

Code example

Add this to your application's application.cr:

require "grip"

class IndexController
  include Grip::Controllers::HTTP

  def get(context : Context) : Context
    context
      .put_status(200) # Assign the status code as 200 OK.
      .json({"id" => 1}) # Respond with JSON content.
      .halt # Close the connection.
  end

  def index(context : Context) : Context
    id =
      context
        .fetch_path_params
        .["id"]

    # An optional secondary argument gives a custom `Content-Type` header to the response.
    context
      .json(content: {"id" => id}, content_type: "application/json; charset=us-ascii")
      .halt
  end
end

class Application
  include Grip::Application

  # You can include as many handlers as you want,
  # for now we will just log the requests and provide an HTTP handler.
  property handlers : Array(HTTP::Handler) = [
    Grip::Handlers::Log.new,
    Grip::Handlers::HTTP.new
  ] of HTTP::Handler

  # By default the environment is set to "DEVELOPMENT".
  property environment : String = 
    ENV["ENVIRONMENT"]? || "PRODUCTION"

  def initialize
    scope "/api" do
      scope "/v1" do
        get "/", IndexController
        get "/:id", IndexController, as: :index
      end
    end
  end
end

app = Application.new
app.run

Installation

Add this to your application's shard.yml:

dependencies:
  grip:
    github: grip-framework/grip

And run this command in your terminal:

shards install

API Reference

Documentation can be found on the official website of the Grip framework or the CrystalDoc website.

Contribute

See our contribution guidelines and read the code of conduct.

探索相关项目

加载中…