Total Blog Views: 74
Blog Status: publish
Created By: swaz_ahmed Created at: 08-22-2024
Tags: Sinatra web Framework Sinatra in Ruby Sinatra Tutorial Sinatra vs Rails Sinatra Routing Sinatra Basics How to install sinatra in ruby Ruby Framework Basic application with Sinatra Sinatra is Gem Or Framework Sinatra Templates Sinatra Gem Sinatra Middleware Sinatra Setup Sinatra Installation Simple Sinatra App Sinatra Framework Basics
Sinatra is a web application framework written in Ruby. It's known for being lightweight and flexible, making it ideal for small to medium-sized applications or microservices. Sinatra allows you to quickly create web applications with minimal effort, as it provides a simple, domain-specific language for defining routes and handling requests.
Sinatra was designed and developed by Blake Mizerany. It is a free and open-source web application library and domain-specific language written in Ruby. It serves as an alternative to other Ruby web application frameworks, such as Ruby on Rails, Merb, Nitro, and Camping. Sinatra is dependent on the Rack web server interface.
Sinatra is small and flexible. It does not follow the typical Model-View-Controller (MVC) pattern used in other frameworks, such as Ruby on Rails. Instead, Sinatra focuses on quickly creating web applications in Ruby with minimal effort. Due to its much smaller size compared to Ruby on Rails, it is also called a microframework.
Inside your project directory, create a file named app.rb
. This will serve as the main file for your Sinatra application.
# app.rb
require 'sinatra'
get '/' do
'Hello, world!'
end
ruby app.rb
get
, post
, put
, delete
, etc., to create various endpoints. Here’s an example with additional routes:# app.rb require 'sinatra' get '/' do 'Welcome to my Sinatra app!' end get '/about' do 'This is a basic Sinatra application.' end post '/submit' do "You submitted: #{params[:text]}" end
Gemfile
in your project directory and specify your dependencies there.# Gemfile source 'https://rubygems.org' gem 'sinatra'
Install Dependencies
After creating your Gemfile
, run the following command to install the dependencies specified within it: bundle install
.
bundle install
Run Your Application with Bundler
bundle exec ruby app.rb
.bundle exec ruby app.rb
In this blog, we have extensively discussed the Sinatra framework—what Sinatra is and why you might choose it over other frameworks. We have successfully set up a basic Sinatra application by following the steps outlined above. With these basics in place, you can now explore more advanced features of Sinatra, such as templates, form handling, and middleware, to build more complex web applications. I hope you enjoyed reading this article on Sinatra.
Interested in diving deeper into web development? Check out my other blog posts:
Learn how to build a comprehensive to-do application using React and Redux.
Setup and Login Sample Page using React
A guide to setting up a sample login page with React for your applications.
Hotwire in Ruby on Rails Applications
Discover how to integrate Hotwire into your Rails applications for faster and more dynamic user experiences.
How to Set Up and Use Ruby on Rails with Oracle Database
Step-by-step instructions for configuring Ruby on Rails to work with Oracle Database.
Deploying Ruby on Rails with Apache2 and Passenger using EC2 Instance: A Step-by-Step Guide
Learn how to deploy a Rails application using Apache2 and Passenger on an EC2 instance.
GraphQL API in a Rails Application
Implement GraphQL APIs within your Rails applications with this detailed guide.
Mastering Internal Dashboards in Rails 7 with ActiveAdmin
Master the creation of internal dashboards using Rails 7 and the ActiveAdmin gem.
Visit my blog channel for more articles and resources..!!
we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.
© Copyright Shadbox. All Rights Reserved
Rate Blog :
Share on :
Do you have any blog suggestion? please click on the link