Giter Site home page Giter Site logo

sinatra-from-scratch-readme-v-000's Introduction

Sinatra From Scratch

Overview

We'll cover the components of a basic Sinatra application and how to create a local host server to view the application in the browser.

Objectives

  1. Review gems and how to keep them updated using bundle install
  2. Describe the purpose of the application controller and app.rb in Sinatra
  3. Run a Sinatra app by entering rackup app.rb in your terminal

Basic Sinatra App

Sinatra Gem

This is not a lab, as there's nothing for you to submit. But to follow along with the lesson, make sure you fork and clone this repository.

It's important to note that Sinatra is just a gem. It's a library of code that developers wrote to allow us to build light-weight web applications quickly. If you take a look at our Gemfile (a list of all the gems our application uses), you will see the Sinatra gem listed.

The first thing you need to do is enter in terminal bundle install. Just like software has different versions that require you to update your mobile apps, gems have newer versions. bundle install will lock in the current versions of the gems for your application. That way, if any updates happen, your app won't break. It keeps the versions locked in a file called Gemfile.lock that is created for you.

app.rb

The app.rb file is the heart and soul of a Sinatra application. This is our application controller. The application controller handles all incoming requests to our app, and sends back the appropriate responses to the client.

The first line of app.rb is just requiring the Sinatra gem so that we can incorporate its functionality.

On the next line, we define a class App and have it inherit from Sinatra::Base. This way, any instance of our class App will have all the functionality of the Sinatra class.

Inside our class we have a Sinatra method define our controller action. This method responds to a GET request to the root url and displays the text Hello, World! in the browser.

Starting The App

To actually check if our app is working in the browser, enter rackup app.rb in your terminal.

Sinatra relies on Rack for its middleware. Because we have the Sinatra gem listed in our Gemfile, we automatically have the Rack middleware setup.

Once your server is running, visit localhost:9292 in the browser to see Hello, World! displayed.

View Sinatra From Scratch on Learn.co and start learning to code for free.

View Sinatra from Scratch on Learn.co and start learning to code for free.

sinatra-from-scratch-readme-v-000's People

Contributors

annjohn avatar victhevenot avatar jmburges avatar interestinall avatar talum avatar jonbf avatar

Watchers

James Cloos avatar Liah Wallace avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.