Sinatra: Up and Running

By Alan Harris, Konstantin Haase

Take good thing about Sinatra, the Ruby-based internet program library and domain-specific language utilized by GitHub, LinkedIn, Engine backyard, and different widespread agencies. With this concise publication, you are going to fast achieve operating wisdom of Sinatra and its minimalist method of development either standalone and modular internet applications.

Sinatra serves as a light-weight wrapper round Rack middleware, with syntax that maps heavily to services uncovered through HTTP verbs, which makes it excellent for net prone and APIs. when you've got event construction purposes with Ruby, you will fast study language basics and spot under-the-hood suggestions, with the aid of numerous useful examples. Then you will get hands-on event with Sinatra by way of development your personal weblog engine.

  • Learn Sinatra's center recommendations, and start via development an easy application
  • Create perspectives, deal with periods, and paintings with Sinatra direction definitions
  • Become accustomed to the language's internals, and take a better examine Rack
  • Use varied subclass tools for development versatile and powerful architectures
  • Put Sinatra to paintings: construct a web publication that takes benefit of provider hooks supplied through the GitHub API

Show description

Preview of Sinatra: Up and Running PDF

Similar Programming books

Joe Celko's SQL for Smarties: Advanced SQL Programming Third Edition (The Morgan Kaufmann Series in Data Management Systems)

SQL for Smarties was once hailed because the first e-book dedicated explicitly to the complex innovations had to remodel an skilled SQL programmer into a professional. Now, 10 years later and within the 3rd version, this vintage nonetheless reigns very best because the ebook written through an SQL grasp that teaches destiny SQL masters.

Designing Audio Effect Plug-Ins in C++: With Digital Audio Signal Processing Theory

Not only one other theory-heavy electronic sign processing booklet, nor one other uninteresting build-a-generic-database programming publication, Designing Audio impression Plug-Ins in C++ delivers every thing you every little thing you must be aware of to do exactly that, together with absolutely labored, downloadable code for dozens audio impression plug-ins and virtually offered algorithms.

Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition)

“Every C++ specialist wishes a replica of powerful C++. it really is an absolute must-read for someone deliberating doing critical C++ improvement. If you’ve by no means learn powerful C++ and also you imagine you recognize every thing approximately C++, re-evaluate. ”— Steve Schirripa, software program Engineer, Google “C++ and the C++ group have grown up within the final fifteen years, and the 3rd variation of potent C++ displays this.

Cocoa Design Patterns

“Next time a few child indicates up at my door requesting a code evaluation, this is often the e-book that i'm going to throw at him. ”   –Aaron Hillegass, founding father of large Nerd Ranch, Inc. , and writer of Cocoa Programming for Mac OS X   Unlocking the secrets and techniques of Cocoa and Its Object-Oriented Frameworks   Mac and iPhone builders are usually beaten via the breadth and class of the Cocoa frameworks.

Additional resources for Sinatra: Up and Running

Show sample text content

Zero. zero. 1... hooked up * attached to localhost (127. zero. zero. 1) port 4567 (#0) > GET /multiple HTTP/1. 1 > User-Agent: curl/7. 19. 7 (universal-apple-darwin10. zero) > Host: localhost:4567 > settle for: */* > < HTTP/1. 1 two hundred okay < Content-Type: text/plain;charset=utf-8 < X-Custom-Value: foo < X-Custom-Value-2: bar < Content-Length: 27 < Connection: keep-alive < Server: skinny 1. 2. eleven codename Bat-Shit loopy < * Connection #0 to host localhost left intact * remaining connection #0 word The HTTP specification defines a couple of normal headers; the generally-accepted conference is to prefix customized or user-defined headers with “X-”, resembling X-Custom-Value. There are a number of non-standard headers which are in universal use: X-Forwarded-For, X-Requested-With, and X-Powered-By are only a couple of. the normal HTTP headers are available at http://www. w3. org/Protocols/rfc2616/rfc2616-sec14. html. Exploring the request item Sinatra exposes various request info through the request item, as visible in instance 2-27. The request item holds a hash of request info comparable to who made the request, what model of the HTTP regular to exploit, etc. We’ll speak about the underlying mechanics of this item extra once we delve into Rack in bankruptcy three. instance 2-27. gaining access to request info require 'sinatra' sooner than do content_type :txt finish get '/' do request. env. map { |e| e. to_s + "\n" } finish This program will iterate over the entire values within the @env variable and show them as output. $ curl http://localhost:9393/ ["GATEWAY_INTERFACE", "CGI/1. 1"] ["PATH_INFO", "/"] ["QUERY_STRING", ""] ["REMOTE_ADDR", "127. zero. zero. 1"] ["REMOTE_HOST", "localhost"] ["REQUEST_METHOD", "GET"] ["REQUEST_URI", "http://localhost:9393/"] ["SCRIPT_NAME", ""] ["SERVER_NAME", "localhost"] ["SERVER_PORT", "9393"] ["SERVER_PROTOCOL", "HTTP/1. 1"] ["SERVER_SOFTWARE", "WEBrick/1. three. 1 (Ruby/1. nine. 2/2011-07-09)"] ["HTTP_USER_AGENT", "curl/7. 19. 7 (universal-apple-darwin10. 0)"] ["HTTP_HOST", "localhost:9393"] ["HTTP_ACCEPT", "*/*"] ["rack. version", [1, 1]] ["rack. input", #>] ["rack. errors", #>>] ["rack. multithread", actual] ["rack. multiprocess", fake] ["rack. run_once", fake] ["rack. url_scheme", "http"] ["HTTP_VERSION", "HTTP/1. 1"] ["REQUEST_PATH", "/"] ["rack. request. query_string", ""] ["rack. request. query_hash", {}] equally, we will be able to iterate over the equipment outlined for the request item for comparability reasons. See instance 2-28. instance 2-28. Enumerating the equipment at the request item require 'sinatra' sooner than do content_type :txt finish get '/' do request. equipment. map { |m| m. to_s + "\n" } finish We’ve truncated the rendered output for brevity, yet you’ll see many of the @env fields represented. $ curl localhost:4567/ settle for preferred_type settle for? safe? forwarded? secure? idempotent? env physique script_name path_info request_method query_string content_length content_type consultation session_options logger media_type media_type_params content_charset scheme ssl?

Download PDF sample

Rated 4.98 of 5 – based on 31 votes