Project

guaraci

0.0
No release in over 3 years
A very simple web framework made with async http
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 0.9

Runtime

~> 2.27.0
~> 0.89.0
>= 0
 Project Readme

☀️ Guaraci

Static Badge Gem Version

Ruby License: MIT

Guaraci is very a simple Ruby web microframework built on top of the powerful Async::HTTP. It was designed to be minimalist, providing a clean and intuitive API with as little overhead as possible.

Its goal is to be minimalist, with a small codebase focused on simplicity, without the need to learn extensive DSLs like other frameworks; it only requires plain Ruby.

Features

  • High performance - Powered by Async::HTTP for non-blocking concurrency
  • Flexible - Easy to extend and customize
  • Lightweight - Few dependencies

Installation

In your gemfiile:

gem 'guaraci'

And run:

bundle install

Or:

gem install guaraci

How to use

Hello World

require 'guaraci'

Guaraci::Server.run(port: 3000) do |request|
  response = Guaraci::Response.ok
  response.json({ message: "Hello, World!" })
  response.render
end

Routing

A little about routing first: I decided to keep the code simple, so no routing dsl and constructors were built. Why? The ideia is to use plain ruby, without the need to learn another DSL apart ruby itself, like rails, sinatra, roda, etc.

I REALLY recommend you to use the new pattern matching feature that comes with Ruby 3.x by default.

require 'guaraci'

Guaraci::Server.run(host: 'localhost', port: 8000) do |request|
  case [request.method, request.path_segments]
  in ['GET', []]
    handle_api_request(request)
  in ['GET', ['health']]
    health_check
  else
    not_found
  end
end

def handle_api_request(request)
  response = Guaraci::Response.ok
  response.json({
    method: request.method,
    path: request.path_segments,
    params: request.params,
    timestamp: Time.now.iso8601
  })
  response.render

##  Or you can pass a block like this
#
#   Guaraci::Response.ok do |res|
#     res.json({
#       method: request.method,
#       path: request.path_segments,
#       params: request.params,
#       timestamp: Time.now.iso8601
#      })
#   end.to_a
end

def health_check
  response = Guaraci::Response.ok
  response.json({ status: 'healthy', uptime: Process.clock_gettime(Process::CLOCK_MONOTONIC) })
  response.render

## Or you can pass a block like this
#
#   Guaraci::Response.ok do |res|
#     res.json({
#       status: 'healthy',
#       uptime: Process.clock_gettime(Process::CLOCK_MONOTONIC)
#     })
#   end
end

def not_found
  response = Guaraci::Response.new(404)
  response.json({ error: 'Not Found' })
  response.render
end

Examples

You can see more examples on how to build guaraci apps inside Examples folder

Development

Clone the repository:

  1. Execute bin/setup to install dependencies
  2. Execute rake test to run tests
  3. Execute bin/console for an interactive prompt

Tests

Its the plain and old minitest :)

rake test

ruby test/guaraci/test_request.rb

bundle exec rubocop

Inspiration

Why this name?

In Tupi-Guarani indigenous culture, Guaraci (Guaracy or Kûarasy) is the solar deity associated with the origin of life. As a central figure in indigenous mythology, and son of Tupã, Guaraci embodies the power of the sun, is credited with giving rise to all living beings, and protector of the hunters.

Its also a word that can be translated to "Sun" in Tupi-Guarani language.

Roadmap

  • Integrated pipeline Middleware
  • Templates support
  • WebSocket support
  • Streaming responses
  • A better documentation
  • More examples on how to use it
  • Performance benchmark

Acknowledgements

  • Async::HTTP - The powerful asynchronous base of this project
  • Wisp - The great framework that I enjoyed using so much and that inspired the philosophy behind building this one

📄 License

MIT License.


Thank you so much, feel free to contact me ☀️ Guilherme Silva