DEV Community

Cover image for Introducing the Macaw Framework: A Simple, Evolving Ruby Web Framework
Aria Diniz
Aria Diniz

Posted on • Edited on

5

Introducing the Macaw Framework: A Simple, Evolving Ruby Web Framework

Hello there! I am excited to introduce you to the Macaw Framework, a Ruby-based web framework that I have been passionately developing. The focus of Macaw is on simplicity and ease-of-use, while still providing powerful features. In this post, I will showcase the framework's core features and guide you through building a basic web application using Macaw. Let's get started!

Setting up Macaw

To begin, install the Macaw gem and create a new file named app.rb. In this file, require the Macaw Framework and create an instance of the Macaw class:

require "macaw_framework"

app = MacawFramework::Macaw.new
Enter fullscreen mode Exit fullscreen mode

Creating HTTP Endpoints with Ease

Macaw offers straightforward methods for creating HTTP endpoints, such as get, post, put, patch, and delete. Each method accepts a path and a block of code that's executed when a request is made to the path. For example, to create a GET endpoint at the path /hello:

app.get("/hello") do |context|
  "Hello, world!"
end
Enter fullscreen mode Exit fullscreen mode

Rate Limiting: Simple and Effective

Enabling rate limiting is easy. Just update your application.json configuration file with the desired rate limiting settings:

{
  "macaw": {
    ...
    "rate_limiting": {
      "window": 60,
      "max_requests": 100
    },
    ...
  }
}

Enter fullscreen mode Exit fullscreen mode

With this configuration, clients will be limited to a maximum of 100 requests per minute.

SSL Support: Secure Your Application

To enable SSL, add the following to your application.json:

{
  "macaw": {
    ...
    "ssl": {
      "cert_file_name": "path/to/your/cert.pem",
      "key_file_name": "path/to/your/key.pem"
    },
    ...
  }
}
Enter fullscreen mode Exit fullscreen mode

Ensure you replace the file paths with the actual paths to your SSL certificate and private key files.

Caching: Improve Performance

To enable caching for a specific endpoint, set the cache parameter to true when creating the endpoint:

app.get("/cached_hello", cache: true) do |context|
  "Hello, world! (cached)"
end
Enter fullscreen mode Exit fullscreen mode

Cache also needs some configuration on the application.json file:

{
  "macaw": {
    ...
    "cache": {
      "cache_invalidation": 3600
    },
    ...
  }
}
Enter fullscreen mode Exit fullscreen mode

Monitoring with Prometheus: Stay Informed

To enable Prometheus monitoring, add the following to your application.json:

{
  "macaw": {
    ...
    "prometheus": {
      "endpoint": "/metrics"
    },
    ...
  }
}
Enter fullscreen mode Exit fullscreen mode

This will enable Prometheus monitoring for your application.

Starting the Server: Ready, Set, Go!

To start the Macaw server, simply call the start! method:

app.start!
Enter fullscreen mode Exit fullscreen mode

This will start the server on the configured host and port.

In summary, the Macaw Framework provides a simple and flexible API for building web applications in Ruby. I am proud of the progress made so far; nevertheless, there is always room for growth and improvement. Check out the Macaw Framework's GitHub repository here and dive into the code! I invite you to join me on this journey and contribute to the Macaw Framework's development, so if you have some time to test and experiment with it, give me your feedback!

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (4)

Collapse
 
alexcastrodev profile image
Alexandro Castro

I love Ruby!
This is a great alternative for Sinatra.

Collapse
 
nezirzahirovic profile image
Nezir Zahirovic

Great work!

Collapse
 
ariasdiniz profile image
Aria Diniz

Thanks!

Collapse
 
moriort profile image
Moriort

Interesting! Thanks for share!

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay