DEV Community

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

Posted on • Updated on

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!

Top comments (3)

Collapse
 
nezirzahirovic profile image
Nezir Zahirovic

Great work!

Collapse
 
ariasdiniz profile image
Aria Diniz

Thanks!

Collapse
 
moriort profile image
Moriort

Interesting! Thanks for share!