ricr
Ricr
An HTTP Router In Crystal, with automatic Swagger/OpenAPI API docs generation.
Features
The Ricr web framework emphasise on type safety. By defining expected types for requests and responses, it also provides documentation.
- Safe by returning an error at startup if routes conflict
- Automatic cast of requests and responses with defined types
- Automatic Swagger/OpenAPI documentation generation
- More type safety with less boilerplates
- Performance (at least on par with other web frameworks)
- Enforce standards (e.g. a
HEAD
route has no request body) - Simple, customizable and modular
Installation
Add the dependency to your shard.yml
:
dependencies:
ricr:
github: ricr-web/ricr
Documentation
https://ricr-web.github.io/ricr
Usage
Simple web server serving "/"
:
require "ricr"
server = Ricr.new
server.controller.add do
get "public" do
"Hello!"
end
post request_body: String do |body|
body
end
end
# For testing URLs
spawn { server.start }
sleep 0.5
server.client.get("/public").body # => "Hello!"
server.client.post("/", body: "hey!").body # => "hey!"
More examples in EXAMPLES.md.
Swagger/OpenAPI documentation generation
Add icyleaf/swagger to the dependencies:
dependencies:
swagger:
github: icyleaf/swagger
Run shards install
require "ricr"
require "ricr/docs"
server = Ricr.new
server.controller.docs_route
server.start
The API docs are now available at http://localhost:3000/docs
.
License
Copyright (c) 2020 Julien Reichardt - ISC License