Sinatra Up and Running.pdf

(6730 KB) Pobierz
813344225.009.png
813344225.010.png
Sinatra: Up and Running
Alan Harris and Konstantin Haase
Beijing
Cambridge
Farnham
Köln
Sebastopol
Tokyo
813344225.011.png 813344225.012.png 813344225.001.png 813344225.002.png 813344225.003.png 813344225.004.png 813344225.005.png 813344225.006.png
 
Sinatra: Up and Running
by Alan Harris and Konstantin Haase
Copyright © 2012 Alan Harris. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles ( http://my.safaribooksonline.com ) . For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com .
Editors: Simon St. Laurent and Mike Hendrickson
Production Editor: Melanie Yarbrough
Proofreader: Melanie Yarbrough
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Robert Romano
Revision History for the First Edition:
2011-11-21 First Release
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Sinatra: Up and Running , the image of a whip-poor-will, and related trade dress are
trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-1-449-30423-2
[LSI]
1321480476
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
1.
Taking the Stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Characteristics of Sinatra
2
Is It a Framework?
2
Does It Implement MVC?
2
Who’s Using It?
3
What Does a Production Project Look Like?
3
What’s the Catch?
4
Are These Skills Transferrable?
4
Installation
4
Thin
4
Up and Running
5
Breaking Down the Syntax
6
Testing with Telnet
8
Rock, Paper, Scissors or “The Shape of Things to Come”
10
Summary
13
2.
Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Routing
15
Hypertext Transfer Protocol
16
Verbs
16
Common Route Definition
18
Many URLs, Similar Behaviors
19
Routes with Parameters
20
Routes with Query String Parameters
21
Routes with Wildcards
21
The First Sufficient Match Wins
21
Routes with Regular Expressions
22
Halting a Request
23
Passing a Request
23
iii
813344225.007.png 813344225.008.png
Zgłoś jeśli naruszono regulamin