Lumen Programming Guide Writing PHP Microservices REST and Web Service APIs 1st Edition Paul Redmond (Auth.) All Chapters Instant Download
Lumen Programming Guide Writing PHP Microservices REST and Web Service APIs 1st Edition Paul Redmond (Auth.) All Chapters Instant Download
com
https://textbookfull.com/product/lumen-
programming-guide-writing-php-microservices-rest-
and-web-service-apis-1st-edition-paul-redmond-
auth/
PHP Web Services APIs for the Modern Web 2nd Edition Lorna
Jane Mitchell
https://textbookfull.com/product/php-web-services-apis-for-the-modern-
web-2nd-edition-lorna-jane-mitchell/
textbookfull.com
https://textbookfull.com/product/integrating-web-services-with-oauth-
and-php-a-php-architect-guide-1st-edition-matthew-frost/
textbookfull.com
https://textbookfull.com/product/php-8-quick-scripting-reference-a-
pocket-guide-to-php-web-scripting-third-edition-mikael-olsson/
textbookfull.com
https://textbookfull.com/product/tautai-samoa-world-history-and-the-
life-of-taisi-o-f-nelson-patricia-obrien/
textbookfull.com
https://textbookfull.com/product/happy-orchid-help-it-flower-watch-it-
flourish-first-american-edition-edition-sara-rittershausen-peter-bull/
textbookfull.com
https://textbookfull.com/product/this-land-is-our-land-an-immigrant-s-
manifesto-suketu-mehta/
textbookfull.com
https://textbookfull.com/product/belonging-identity-time-and-young-
people-s-engagement-in-the-middle-years-of-school-seth-brown/
textbookfull.com
https://textbookfull.com/product/professional-communication-
consultancy-advocacy-activism-louise-mullany/
textbookfull.com
Crop Rotation An Approach to Secure Future Food Samiha
Ouda
https://textbookfull.com/product/crop-rotation-an-approach-to-secure-
future-food-samiha-ouda/
textbookfull.com
Lumen
Programming
Guide
Writing PHP Microservices, REST and
Web Service APIs
—
Paul Redmond
Lumen
Programming Guide
Writing PHP Microservices, REST
and Web Service APIs
Paul Redmond
Lumen Programming Guide: Writing PHP Microservices, REST and Web Service APIs
Paul Redmond
Phoenix, Arizona
USA
ISBN-13 (pbk): 978-1-4842-2186-0 ISBN-13 (electronic): 978-1-4842-2187-7
DOI 10.1007/978-1-4842-2187-7
Library of Congress Control Number: 2016953766
Copyright © 2016 by Paul Redmond
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director: Welmoed Spahr
Lead Editor: Steve Anglin
Technical Reviewer: Jacob Jensen
Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black, Louise Corrigan,
Jonathan Gennick, Robert Hutchinson, Celestin Suresh John, Nikhil Karkal, James Markham,
Susan McDermott, Matthew Moodie, Natalie Pao, Gwenan Spearing
Coordinating Editor: Mark Powers
Copy Editor: Mary Behr
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Cover image designed by Freepik
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.
eBook versions and licenses are also available for most titles. For more information, reference our Special
Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales.
Any source code or other supplementary materials referenced by the author in this text are available to
readers at www.apress.com/9781484221860. For detailed information about how to locate your book’s source
code, go to www.apress.com/source-code/. Readers can also access source code at SpringerLink in the
Supplementary Material section for each chapter.
Printed on acid-free paper
To Bernadette
Contents at a Glance
v
Contents
Windows ........................................................................................................................... 6
Conclusion ........................................................................................................................ 6
■Chapter 2: Hello Lumen ......................................................................................... 7
Setting Up a New Project ................................................................................................. 7
Routes .............................................................................................................................. 9
The Hello World Route .......................................................................................................................... 10
Route Parameters ................................................................................................................................. 10
vii
■ CONTENTS
Onward ........................................................................................................................... 16
■Chapter 3: Creating the Book Application ........................................................... 17
Building Something Amazing ......................................................................................... 17
Environment Setup ......................................................................................................... 19
Checking Unit Tests ........................................................................................................ 21
Setup Complete .............................................................................................................. 22
■Chapter 4: Starting the Books API ....................................................................... 23
Creating the First Endpoint............................................................................................. 23
Setting Up Models and Seed Data .................................................................................. 26
Eloquent Books .............................................................................................................. 30
Success .......................................................................................................................... 32
■Chapter 5: Creating, Reading, Updating, and Deleting Books .............................. 33
Requesting an Individual Book ....................................................................................... 33
Creating a New Book ...................................................................................................... 41
Updating an Existing Book ............................................................................................. 49
Deleting Books ............................................................................................................... 53
Conclusion ...................................................................................................................... 63
■Chapter 6: Responding to Errors ......................................................................... 65
Test Database ................................................................................................................. 65
Model Factories .................................................................................................................................... 66
Factories in Tests .................................................................................................................................. 66
ix
■ CONTENTS
x
About the Author
xi
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
About the Technical Reviewer
xiii
Acknowledgments
xv
Introduction
Lumen is a framework that is designed to write APIs. With the rising popularity of microservices
(http://microservices.io/patterns/microservices.html), existing patterns like service-oriented
architecture (https://en.wikipedia.org/wiki/Service-oriented_architecture), and increased
demand for public APIs, Lumen is a perfect fit for writing the service layer in the same language as the web
applications you write.
In my experience, it’s not uncommon for PHP shops to write web applications with PHP and API
services with something like Node.js (https://nodejs.org/en/). I am not suggesting that this is a bad idea,
but I see Lumen as a chance to improve development workflows for PHP developers and for companies to
standardize around a powerful set of complimentary frameworks: Laravel and Lumen.
You can write APIs quickly with Lumen using the built-in packages provided, but Lumen can also get out
of your way and be as minimalist as you want it to be. Set aside framework benchmarks and open your mind
to increased developer productivity. Lumen is fast, but more importantly, it helps me be more productive.
xvii
■ INTRODUCTION
Code Examples
A typical PHP code snippet looks like this:
To guide readers, approximate line numbers are used when you will be adding a block of code to an
existing class or test file:
Longer lines end in a backslash (\) and continue to the next line:
When you need to run console commands to execute the test suite or create files, the snippet appears as
plain text without line numbers. Lines start with $, which represents the terminal prompt.
Console commands that should be executed in the recommended Homestead1 environment will be
indicated like the following example. The book removes extra output from PHPUnit tests to make examples
less verbose.
OK (1 test, 4 assertions)
1
https://laravel.com/docs/homestead
xviii
■ INTRODUCTION
This is an aside
Hey, Listen! Tips give you pointers related to concepts in the book.
Need the Info This aside provides additional info related to code and concepts.
This is an example of a code commit if you are following along and using git to commit your work.
Discussions This tip includes deeper discussions around topics in the book. Advanced users can
generally skip these.
VirtualBox
This book uses a virtual machine to run the API application. You will need to download VirtualBox if you
plan on using the recommended Homestead environment. VirtualBox works on Windows, Mac, and Linux
(www.virtualbox.org).
xix
■ INTRODUCTION
Vagrant
Homestead also requires Vagrant (www.vagrantup.com/) to manage and provision virtual machines. Vagrant
works on Windows, Mac, and Linux (Debian and CentOS).
Version Control
If you want to work along in the book and commit your code as you go (recommended), you need to install a
version control system. I recommend git, but anything you want will do.
Editor/IDE
Most readers will already have a go-to editor. I highly recommend PhpStorm (www.jetbrains.com/phpstorm/),
which is not free, but it pays for itself. Other common IDE options are Eclipse PDT and NetBeans.
If you don’t like IDEs, I recommend Sublime Text (www.sublimetext.com/) or Atom (https://atom.io/).
If you are on Mac, TextMate (https://macromates.com/) is another great choice. TextMate 2 is marked as
“beta” but is reliable.
xx
CHAPTER 1
Installing Lumen
Before you start diving into Lumen, you need to make sure PHP is installed. You’ll also need a few other tools
to develop a real application. You can get PHP a number of ways, but here is my recommendation for all
platforms: Laravel Homestead (laravel.com/docs/homestead). I also include a few different ways to install
PHP locally if you are interested, but the book examples will use Homestead. I highly encourage using
Homestead to work through this book.
To work through the applications in this book, you will need
• PHP >= 5.5.9, as well as a few PHP extensions
• Composer
• MySQL Database
Homestead comes with a modern version of PHP called Composer (https://getcomposer.org/), and
a few database options, so you don’t need to worry about the requirements if you are using Homestead; if
you are not using Homestead, you will need >= PHP 5.5.9 as outlined by the Lumen installation instructions
(https://lumen.laravel.com/docs/5.2/installation#installation).
The last thing on the list is a database. Lumen can be configured to use different databases including
MySQL, SQLite, PostgreSQL, or SQL Server. We will use MySQL (any MySQL variant will do) for this book.
MySQL is the default database connection in the Lumen Framework database configuration (https://github.
com/laravel/lumen-framework/blob/5.2/config/database.php) so we will stick with the convention.
Homestead
Laravel Homestead is the best development environment choice because it provides a complete
development environment for all your Laravel and Lumen projects. Homestead provides some solid benefits
for your development environment as well, including the following:
• Isolated environment on a virtual machine
• Works on Windows, Mac, and Linux
• Easily configure all your projects in one place
As mentioned in the introduction, Homestead requires Vagrant (www.vagrantup.com/) and VirtualBox
(www.virtualbox.org/) so you will need to install both. Follow the installation instructions
(https://lumen.laravel.com/docs/5.2/installation#installation) to finish setting up Homestead.
Once you complete the installation instructions you should be able to run the vagrant ssh command
within the Homestead project and successfully ssh into your Homestead virtual machine. You will revisit
Homestead to set up your sample application in Chapter 2, and then you will set up another application in
Chapter 3 that you will work on throughout the remainder of the book.
When the install instructions instruct you to clone the Homestead git repository, I encourage you
to clone it to ~/Code/Homestead to follow along with the book, or you can adapt the examples to match
whatever you pick (see Listing 1-1).
Once you finish the Homestead installation instructions you should be able to ssh into the virtual
machine (Listing 1-2).
* Documentation: https://help.ubuntu.com/
Last login: Tue Feb 2 04:48:52 2016 from 10.0.2.2
vagrant@homestead:~$
You can type “exit” or press Control+D to exit the virtual machine. The homestead repository will be
at ~/Code/Homestead and this is the path you will use in this book for your applications. I encourage you
to review the Homestead.yaml file at ~/.homestead/Homestead.yaml after you finish installing Homestead.
Once you get Homestead installed, you can skip ahead to Chapter 2. See you in the next section!
■ Optional Local Instructions The following sections offer information if you are interested in running PHP
locally, so feel free to skip them. I cannot guarantee these instructions, but for the most part they should work
for you.
Mac OSX
If you want to develop locally on OS X, I recommend using Homebrew (http://brew.sh/) to install PHP
and MySQL. The PHP installation that ships with OS X will probably suffice, but I will show you how to
install PHP with Homebrew instead of dealing with the different versions of PHP that ship with different
versions of OS X.
To install packages with Homebrew, you will need Xcode developer tools and the Xcode command line
tools. XCode is a rather large download—I’ll be waiting for you right here.
Once you have Xcode, follow the installation instructions (http://brew.sh/#install) on Homebrew’s
site. Next, you need to tell brew about “homebrew-php” so you can install PHP 5.6 (Listing 1-3).
2
CHAPTER 1 ■ INSTALLING LUMEN
Once the installation finishes, verify that you have the right version of PHP in your path (Listing 1-4).
Next, you need to install the MySQL database server with Homebrew (Listing 1-5).
Once the MySQL installation is finished, make sure you can connect to the database server (Listing 1-6).
Linux
Here are simple instructions to install PHP on Unix-like systems; this section includes the most popular
distributions like CentOS and Ubuntu. This is not an exhaustive set of setup instructions but it should be
enough to work with Lumen.
3
CHAPTER 1 ■ INSTALLING LUMEN
Red Hat/CentOS
To install a modern version of PHP on Red Hat and CentOS, I recommend using the Webtatic (https://
webtatic.com/) yum repository. First, add the repository with the Webtatic release RPM; you should use the
repository that matches your specific version (Listing 1-7).
# CentOS/REHL 6
$ yum -y update
$ rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
Next, install the following PHP packages and verify that PHP was installed properly (Listing 1-8).
# Verify
$ php --version
PHP 5.6.16 (cli) (built: Nov 27 2015 21:46:01)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
Once MySQL is installed, you should set a root password (Listing 1-10).
4
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
CHAPTER 1 ■ INSTALLING LUMEN
Debian/Ubuntu
On Debian systems I recommend using the php5-5.6 PPA (https://launchpad.net/~ondrej/+archive/
ubuntu/php5-5.6) from Ondrej Surý (https://launchpad.net/~ondrej) or the PHP 7 version of the same
PPA. Installation of the PPA varies slightly between different versions. Most of the steps will remain the same,
but the following are the steps for Ubuntu 14.04 and Ubuntu 12.04.
First, install a couple dependencies needed to add the PPA. If you are using Ubuntu 14.04, see Listing 1-11.
Listing 1-11. Installing Dependencies Needed and the PPA on Ubuntu 14.04
$ apt-get install -y language-pack-en-base
$ apt-get install -y software-properties-common --no-install-recommends
$ LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php5-5.6
If you are using Ubuntu 12.04, run the code in Listing 1-12 instead.
# Verify
$ php --version
PHP 5.6.16-2+deb.sury.org~precise+1 (cli)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
Next, install MySQL server and client packages, make the MySQL service start on boot, and start the
service manually (Listing 1-14).
5
CHAPTER 1 ■ INSTALLING LUMEN
During the installation of the mysql-server package you should be prompted to update the root
password, which will look similar to Figure 1-1.
Verify that you can connect to MySQL after you finish installing MySQL and setting a root password
(Listing 1-15).
At this point, you should have everything required to get through this book using the built-in PHP server
on a local Ubuntu machine.
Windows
I recommend using Homestead (http://laravel.com/docs/5.1/homestead#installation-and-setup) to
work through this book on Windows.
Conclusion
You should now have a working environment that you can use to write Lumen applications! Let’s summarize
what we did in this chapter:
• Installed Vagrant and VirtualBox
• Installed the Homestead virtual machine
• Covered alternative ways of installing PHP and MySQL
I want to emphasize how easy Homestead makes getting a solid, portable development environment
working with little effort. Now that you have PHP installed, it’s time to learn Lumen!
6
CHAPTER 2
Hello Lumen
Let’s dive right into Lumen. In this chapter, you’ll learn how to set up a new Lumen project and you’ll explore
some of Lumen’s basic features:
• Routing
• Middleware
• Requests
• Responses
To follow along, you should have the recommended Homestead environment from Chapter 1 installed.
The book examples assume Homestead was cloned to the suggested path ~/Code/Homestead. Adjust the
commands if you cloned Homestead elsewhere.
In the Homestead virtual machine, you change the directory to ~/Code, where your application files will
live. Next, you use Composer’s create-project command to create a new Lumen project. The last argument
in the create-project command tells Composer to create the project in the path ~/Code/hello-lumen. Now
that you’ve created a new project on the virtual machine, you should also see a shared local path at ~/Code/
hello-lumen on your own machine.
The next step is telling Homestead about the hello-lumen application. On your local machine, open
~/.homestead/Homestead.yaml and find the default project under the sites key (Listing 2-2).
Replace it with the code in Listing 2-3 and save the file.
Configure the project’s hostname and the path to the public folder on the virtual machine. Save the
file and run vagrant provision on your local machine to update Homestead with the new configuration
changes (Listing 2-4).
Every time you update Homestead.yaml you will need to run the vagrant provision command.
Once Vagrant is finished provisioning the machine, the last step is adding an entry to the hosts file on
your local machine. The hosts file will map the hostname hello-lumen.app to your virtual machine’s IP
address. You can find Homestead’s IP address by finding the ip key in the ~/.homestead/Homestead.yaml
file—you should see something like ip: "192.168.10.10".
Take note of the IP address so you can add it to the local hosts file. To update the hosts file on Mac or
Linux, the file path is /etc/hosts; if you are on Windows, the file path is C:\Windows\System32\drivers\
etc\hosts. Add the line from Listing 2-5 to your hosts file.
Be sure to use the IP address found in your ~/.homestead/Homestead.yaml file, not the IP shown in this book.
It might be the same, but make sure.
After updating the hosts file, visit http://hello-lumen.app/ in your browser and you should see
something similar to Figure 2-1.
8
CHAPTER 2 ■ HELLO LUMEN
You should now have a working hello-lumen project. Let’s get to work!
Routes
Routing (https://lumen.laravel.com/docs/5.2/routing) is the first feature we will cover. Application
routes in Lumen are defined in the app/Http/routes.php file. In the most basic form, routing configuration
includes an HTTP verb (GET, POST, etc.) which accepts a URI and a Closure. We will use the Closure style
routes in this chapter, but we will use controllers throughout the book.
The first routes will be two simple “Hello World” examples to introduce you to routing:
• /hello/world which responds with the text “Hello World”
• /hello/{name} which responds with a customized greeting
Before you define your own routes, if you open the file app/Http/routes.php, the default contents
looks like Listing 2-6.
The $app variable in the routes file is an instance of \Laravel\Lumen\Application which is defined
in the bootstrap/app.php file. The application routes file is imported near the end of bootstrap/app.php
(Listing 2-7).
9
Random documents with unrelated
content Scribd suggests to you:
“Yes, yes, I know; but—but——” She stared around her. “I—I—
where is the tent, and the horses?”
“You’ve had a nightmare, and it did us a heap o’ good,” broke in
Sam Barringford. “Your runnin’ around has scared off some redskins,
I reckon.”
By this time half a dozen were near. They gazed at the red warrior
whom Barringford had laid low.
“He is done for,” said Rodney. “He is too far gone even to question
him.” But even as the young soldier spoke the red man raised up
suddenly and flung his tomahawk squarely at Barringford. The fling
was a weak one and the weapon fell short of its mark. Then the
warrior sank back, gave a gasp, and was dead.
“Game to the last,” muttered Barringford. “Don’t know as I blame
him. Might be I’d do likewise, ef one o’ the varmin plugged me,” he
added philosophically.
It took several minutes for Mrs. Dobson to settle herself. Her
husband stated that she often arose in her sleep. She had been
terribly worked up over the red men ever since leaving Fort Pitt, and
this had gotten on her nerves.
The alarm kept the entire camp “on edge” until daybreak.
Barringford and two others made several tours in the immediate
vicinity, but could see or hear nothing more of the enemy.
“They have either cleared out entirely, or else they know how to
hide,” said the old frontiersman.
“Do you think it is the same party that Packerson met?”
questioned Rodney.
“Like as not, Rodney. We ain’t seen or heard o’ anybody else on
this trail.”
They went on as before, and the following forenoon made a
discovery that filled even the stoutest of them with horror. Coming to
a spot where the road led down to a ford over a good-sized brook
they beheld a man lying beside a rock, with one ear gone and part
of his scalp cut away. The man was shot through the body and was
all but dead.
“Who shot you?” asked one of the frontiersman, running up.
“Th—the Indians,” was the low and hoarse answer. “Water!”
Water was brought, but the man was almost too weak to drink.
One of the party recognized him as Stephen Banoggin, a trader well
known in those days around Carlisle and Bedford. Banoggin had left
Bedford ten days before, with a view of establishing a new trading
post in the vicinity of Venango as soon as it seemed safe to do so.
“All dead—all killed by the Indians!” was about all he could say.
“Fool, fool that I was to attempt it! All dead!” And that night he
expired.
His tale was almost true, although not quite so. His pack-train had
consisted of ten horses and nine men, including three negroes who
were his slaves. The Indians—a mixed band under a chief called
Crow Feather—had ambushed the train at the ford and slained or
mortally wounded all but one negro and a white hunter named
Sturm, a German from upper Pennsylvania. Sturm and the negro got
away together, each however wounded. They traveled for four
weeks in the forest, when Sturm went crazy. At last they reached a
settlement, where the negro told his story. Sturm was placed under
medical care and regained his reason some time later.
The sights presented to Rodney and the others at the ford were so
revolting that Mrs. Dobson, Nell, and the twins were held back, that
they might not see what had occurred. The slain were all scalped
and an effort had been made to burn one at the stake. The bodies of
the men and the dead horses lay together. Four horses were
missing, and on these the Indians had packed such stores as they
wanted, scattering the other goods or burning them.
“This is enough to make one sick!” said Rodney, as he turned
away with a shudder. “These redskins must have been fiends!”
“They were certainly cold-blooded,” answered Barringford. “Poor
Banoggin! He had better have stayed in the east.”
“Sam, this doesn’t look as if it would be safe for us to go any
further.”
“Easily said, lad; but what are ye goin’ to do?”
“You mean it is as safe to go forward as to turn back?”
“Don’t it look thet way?”
“Maybe. But we are a little closer to Fort Pitt than we are to Fort
Cumberland.”
“Thet’s true too. But I don’t reckon the Injuns will dare to go as
far east as Cumberland—not after the lickin’ they got at Bushy Run.”
“The band that did this can’t be the band that tried to surround
us.”
“No, they are another tribe, I think.”
“Then the forest must still be full of wandering bands, and we are
not near as safe as we thought we were.”
“We’ve got to make the best on’t, Rodney. We must travel as fast
as we can and keep our eyes peeled more’n ever before. It’s the
only way out, so far as I kin see.”
The bodies of the slain were placed in a hollow, with some flat
stones on top, to keep off the wolves and other wild beasts. The
place was marked on the trees. A few of Banoggin’s possessions
were taken along and the others left where they had fallen.
“Poor fellow, he will never want anything in this life again,”
murmured Rodney, brokenly. And when the trader died they placed
his body away with those of his followers. Fortunately he had been a
bachelor, so there would be no widow or child to mourn his loss.
Early in the morning Rodney and those with him moved on again.
Everybody in the party was exceedingly sober. All realized their great
danger. The fate of Stephen Banoggin and his party was ever before
their eyes and in their thoughts.
CHAPTER IX
UNDER THE CLIFF
The volley poured into the Indians by the whites made the red
warriors pause for the time being. They were close to a clump of
bushes and trees growing near the center of the glade, and they got
behind this shelter with alacrity.
In the cave all was confusion. It was an opening ten to fifteen feet
in height and equally broad at the mouth. It ran back a distance of
over two hundred feet, where it ended in a split among the rocks,
coming out at a point where there was a thick patch of nettle
bushes.
The horses had been brought into the cave and were led to the
rear. Here Hempser worked like a Trojan, with one of the regulars
helping him. Loose stones were to be had in plenty, and they
blocked up the rear opening completely.
“They’ll have their hands full, getting in this way,” said the regular.
“The nettles will keep them back if nothing else will.”
“Right you are,” answered Hempser. “Injuns don’t like to git
scratched any more than anybody else.”
At the front of the cavern Sam Barringford took command. A
glance showed him how the land lay, and he at once ordered some
of the men to pile up the loose stones to a height of several feet.
This formed a barricade, behind which the frontiersmen and regulars
could lie with but little danger of the enemy picking them off.
“This is a situation we didn’t bargain for,” said Rodney, after the
construction of the barricade had come to an end. “I must say I
don’t like it.”
“Well, lad, it’s better than being surrounded in the open,”
answered Barringford, with an effort to look on the bright side of the
affair.
“I don’t think they’ll attack us now,” went on the young soldier.
“But they may do it to-night.”
“We’ll have to keep on guard, and shoot the first man who shows
himself,” put in Casbury.
“Maybe they’ll try to starve us out,” came from another of the
frontiersman.
“We’ve got rations enough for a week or more, on a pinch,” said
Rodney. “We’ve got our regular things and also that deer Barton shot
early this morning, and some rabbits.”
“How about water?” asked another.
“We’ll have to see about that,” said Sam Barringford.
Satisfied that the Indians did not contemplate an immediate
attack, the old frontiersman, accompanied by Rodney, made a tour
of the cave, lighting a torch for that purpose. In one corner the
rocks were found to be very damp, and when some were pulled up a
little water trickled forth.
“Thar’s a spring thar,” said Barringford, with satisfaction. “We kin
do a bit o’ diggin’ an’ then have all the water we wish.” A little later
two of the regulars set to work, with pike-poles and shovels, and
soon had a hollow made into which the water flowed to a depth of
several inches. The water was brought up in a dipper, and proved to
be both clear and wholesome.
As the time slipped by the whole party became more composed,
and Nell and the twins clamored for their delayed dinner. A meal was
prepared in the cave, which the men ate while on the watch.
“Oh, Rodney, will the bad Indians catch us in here?” asked Nell, as
she came up to her elder brother.
“I think not, Nell,” he answered, hopefully.
“I wish I was home.”
“So do I, Nell—wish it more for your sake than for my own.”
“Tom wants to go out and fight the bad Indians,” said one of the
twins. He had picked up a rifle resting against the wall and was
trying to shoulder the long weapon.
“Here, you give me that gun!” cried Rodney, reaching for it. “Tom,
you mustn’t play with the guns. One of ’em might go off and hurt
you.”
“Tom ain’t ’fraid of no gun,” said the little boy. “Want to shoot the
Indians.”
“You keep quiet and stay with Mrs. Dobson or Nell.”
“How long will we have to stay here, Rodney?” asked his little
sister.
“I can’t answer that question, Nell. It depends on the Indians.
Perhaps they’ll get tired of watching us and go away.”
It was a hard matter to keep the twins quiet, but presently both
grew tired of wandering around the cave, and went to sleep on a
pair of blankets spread out for them. Mrs. Dobson sat on one of the
packs with Nell beside her and her husband not far off.
“Oh, Asa, how foolish we were to come out to this western
country!” sighed the woman, for at least the fiftieth time. “We
should have stayed at home and been content with what we had!”
“Ain’t no uset to cry over spilt milk,” grumbled her husband.
“I think the Indians will come to-night and scalp all of us!”
“Oh, Mrs. Dobson, you don’t mean that!” gasped little Nell.
“Don’t scare the little girl, Mrs. Dobson,” put in Casbury, who
chanced to be near. “It won’t help matters to git anybuddy worked
up.”
At last the sun sank in the west and it began to grow dark at the
mouth of the cave. Two men were stationed at the spot where the
rear opening had been, and all the others gathered at the front.
Then Sam Barringford called Rodney to him.
“I’m a-goin’ out on a scoutin’ tour,” said the old frontiersman. “I’m
a-goin’ to leave you an’ Casbury in charge until I git back. Don’t
shoot me, but don’t let none o’ them Injuns git near, nuther.”
“Don’t you want me to go with you, Sam?”
“No, it will be hard enough fer one to git around, let alone two. Ef
ye ain’t sure it’s me comin’ back, hoot like an owl an’ I’ll answer like
a catbird, understand?”
“Yes.”
Barringford gave the others a few directions and then, stepping
quickly over the rocks, snaked his way along through the grass to a
fringe of low bushes. From the bushes he made for the rough rocks,
where he paused, to consider the situation in all of its details.
The old frontiersman felt that he was surrounded by enemies fully
as alert as himself and ready to shoot him down on sight.
“An’ they won’t ax me if I’ll like it nuther,” he murmured to himself.
“They be jest a-hankerin’ arter my sculp like all possessed.”
Peering cautiously around, he saw nobody, and after a short wait
took his way between the rocks towards the spot where the rear of
the cave was located. Here he listened again, and this time heard
the low murmur of two voices. But they were those of Dobson, the
settler, and a regular, talking from inside.
“They ought to know enough to keep quiet,” mused the old
frontiersman, in disgust. “How can they spot the enemy if they gab
like thet?”
In a few minutes the voices ceased, and thinking the coast clear
the old frontiersman worked his way among the rocks and through
the bushes toward a point he imagined the Indians might be
holding. The darkness of night had now fallen completely over the
forest and scarcely a sound broke the stillness.
Barringford was about to cross to another patch of brushwood
when the distant call of a night bird arrested his attention. He was
well versed in the calls of all birds and that which he heard did not
sound exactly true to his ear. He smiled grimly to himself and
waited.
As he had surmised, an answering call soon followed. It came
from the very brushwood he had been on the point of entering, and
a tall Indian stepped forth, as if to advance. Before Barringford could
retreat or draw to one side the pair were face to face.
Not a word was uttered—indeed, there was no time for speech.
The Indian had his tomahawk in his hand, and this he raised, aiming
a blow at the old frontiersman’s skull. As old as he was getting,
Barringford was still nimble on his feet and dexterously dodged to
one side. As the arm of the red warrior came down, he caught the
red man by the shoulder, and over went the pair on the soil. Then
the Indian tried to cry out, but Barringford’s hand was clapped on his
mouth.
It now became a desperate but silent struggle for life. From the
red man’s mouth, the old frontiersman’s hand was shifted to his
throat, which was caught with a grip of steel. The Indian struggled
desperately, first kicking heavily and then drawing up a knee against
Barringford’s breast. Then he tried to use his tomahawk again, and
hit the frontiersman a glancing blow on the shoulder. The hatchet
fell, and in a twinkling the Indian had Barringford by the throat, in a
clutch equally firm and relentless.
Like two bulldogs that have a death-grip and will not let go, white
man and Indian rolled over and over, on the rocks and in the bushes,
each doing all in his power to get the better of the other. The Indian
was muscular, and his strength was equal if not superior to that of
his white adversary. But Barringford had secured the first grip, and
the red man’s breath was fast leaving him. His tongue stuck out, his
eyes bulged from their sockets, and he could not utter even so much
as a faint gurgle.
It was at this moment that an interruption came. Another form
glided into the midst of the bushes. It was a second Indian, and a
glance showed him the condition of affairs. Without stopping to use
his tomahawk or his knife he kicked Barringford heavily in the left
ear. Then followed other blows, and with a groan the old
frontiersman stretched out on the rocks unconscious.
As the hold on his throat relaxed the Indian who had been in the
death struggle gave a gasp and stared about him. The coming of his
fellow warrior had undoubtedly saved his life.
“Where did that white man come from?” asked the second Indian,
as he gave Barringford a close look.
“Cushina knows not,” was the faint reply. It was some time before
the other could get back his breath.
“Are there others about?”
At this question Cushina shrugged his shoulders.
“Did he come from the cave, think you?”
“Perhaps—all of the whites were driven to that shelter, like so
many dogs of the prairie.”
“It may not be so. Others may be at hand. We must be careful.
Moon Eye has news of some soldiers. They may be marching in this
direction.”
“Then Moon Eye himself is here?”
“Yes.”
The first warrior drew a long breath and then brought from his
girdle a keen hunting knife. He felt of its edge with satisfaction.
“Mist of the Lake has come to the aid of Cushina and has brought
the white man to grief,” said he, looking at the other closely. “Does
Mist of the Lake claim the scalp?”
At this query the second Indian shrugged his shoulders.
“Does Cushina still wish to linger in the footsteps of Laughing Eyes
and make her his bride?” he asked, after another pause.
Cushina winced at this question. Both he and Mist of the Lake
were in love with the same Indian maiden. As Mist of the Lake had
saved his life he was bound, according to the laws of his tribe, to
give his rival a clear field in his wooing.
“Laughing Eyes is Mist of the Lake’s—if she will have him,” he said,
in a low voice.
“And the scalp of the white man belongs to Cushina,” was the
prompt reply of the other warrior. “He can take it at his pleasure.”
CHAPTER XI
IN WHICH WHITE BUFFALO APPEARS
The route to the river was a rough one, over jagged rocks and
around stunted growths of evergreens and elderberry bushes, with
here and there a bramble bush or a tangle of wild grapes. Often the
men stumbled, and it was with difficulty that the horses got through
without throwing their loads.
Not a word was spoken, Rodney cautioning all to silence. Every
eye and ear was on the alert. Who knew but what they might be
running into an ambush of the worst kind?
When the watercourse was gained,—a small stream flowing to the
southeastward,—they came to a halt in a small grove of hemlocks
and walnuts. Not another Indian had appeared, for which all were
thankful.
The din to the northward was now growing less, and Rodney was
certain that White Buffalo and his handfuls of braves were in retreat,
not daring to meet the superior force under Moon Eye.
On gaining the vicinity his Indian friend had mentioned to him,
Rodney lost no time in looking around for Sam Barringford.
“Sam!” he called, softly. “Sam, are you here?”
“Rodney!” came in a weak voice. “Here I be—an’ glad ye have
come!”
The old frontiersman was up in a short, wide-spreading tree,
where White Buffalo and another friendly red man had placed him.
He was weak from his encounter with the enemy and glad to have
the young soldier and the others come to his aid.
“I had what ye might call a putty clost shave,” said Barringford.
“They got me down an’ one o’ the rascals war a-goin’ to sculp me
when Moon Eye cuts in an’ says to let me alone—he would torture
me into tellin’ em’ some o’ the white folks’ secrets—about the fort
an’ the soldiers on the march, an’ sech. They war a-goin’ to burn me
at a stake—jest as them Injuns war goin’ to burn me when I war on
my way to Detroit with Dave,—when White Buffalo plays a trick on
’em.”
“What did he do, Sam?”
“Got one o’ his followers to wave a torch from some rocks. The
feller war kivered with a white blanket an’ I reckon they took him fer
a ghost. When Moon Eye’s crowd war lookin’ at the figger in white,
White Buffalo come up to me, fixed up as one o’ the enemy, an’ cuts
me loose. I didn’t know him myself till he spoke. The disguise did
the trick, and we got away into the forest. Then I dropped, I war
thet weak, and they brung me here. Then he said he would do what
he could fer ye—an’ he must have kept his word, or ye wouldn’t be
here,” concluded the old frontiersman.
White Buffalo had mentioned another spot—down the river—
where the party of whites might wait until morning for the
Delawares to join them. Helping Sam Barringford upon one of the
horses that had been carrying supplies, they set off for the place
mentioned, reaching it without mishap just as day was breaking.
By this time the entire party was so worn out that half the number
were glad to throw themselves down to rest, leaving the others on
guard for two hours, when they were relieved by their companions.
A light breakfast was served, no campfire being lit for fear the
smoke might attract the attention of the enemy.
It was well toward noon when White Buffalo came in, he and his
followers having had to make a wide detour, in order to escape
another encounter with Moon Eye. White Buffalo had been struck in
the left forearm by a tomahawk, an ugly but not a serious cut, and
one brave had received an arrow in the fleshy part of the leg.
“Do you think they are coming this way?” was Rodney’s first
question.
“There is no telling what they will do next,” answered the aged
Indian chief. “White Buffalo and his followers drew them as far
northward as possible—we could do no more. Rodney had better
travel eastward as fast as he can. In that direction alone lies safety.”
Without delay the march was once more begun, first to a fording
spot across the stream and then directly eastward. They moved
onward until long after sunset, covering at least fifteen miles, over a
broken deer trail that was rough in the extreme. On the way one
horse—that carrying Nell and little Tom—stepped into a hole and
went down, throwing both children into the bushes.
“Are you hurt, Nell?” asked Rodney, rushing up in alarm.
“I—I think not!” she gasped. “But I don’t like such tumbles at all!”
“Bad horse, to go down with Tom,” said the little boy.
“He couldn’t help it,” answered Rodney. “I am glad you are not
injured,” he added, heartily, and picked the boy up in his arms while
Nell arose unaided.
The horse was in a bad way, having broken his leg and dislocated
his shoulder. To put him out of his misery, Rodney had one of the
Indians kill him with several blows from a tomahawk. Then Nell and
Tom were placed on another horse, and the party went on as before.
The next day found them once more on the regular road. Not a
sign of the enemy had been seen and all began to breathe a little
easier.
“I think we are out of it at last,” said Rodney. “We are getting
pretty well on to the east now.”
“Right you are,” answered Casbury.
“That White Buffalo is a pretty good Injun after all, so he is,”
admitted Malloy.
They had now reached what in past years had been the foremost
of the homesteads along the army road. The places were burned
down without exception, only the blackened ruins showing where log
cabins and stables had stood. The owners had long since either fled
or been killed.
“It may be a long while before this is settled again,” said Rodney.
“Perhaps not, lad,” answered one of the frontiersmen. “As soon as
it is known the Indians are under control some folks will come out
again, and others will follow,” and this proved to be true. Inside of
three years there were more settlements along the Forbes and the
Braddock roads than ever before.
Feeling themselves fairly free from danger, they did not push
along quite so rapidly. This rested the horses and was also more
comfortable for Sam Barringford, who had suffered more than he
cared to admit.
“Rodney will not want White Buffalo any more,” said the aged
chief one morning, when they were within two days’ journey of Fort
Cumberland. “White Buffalo must go elsewhere.”
“Won’t you come home with me?” asked the young soldier. “Father
will be glad to see you, I know.”
“White Buffalo must attend to the affairs of his tribe,” was the
reply, and soon the aged chief departed with his followers, stating
that if it was possible he would stop at Fort Pitt and let James
Morris, Dave, and Henry know how they had come through without
great loss. Rodney thanked the Indian for all he had done and shook
hands warmly, and Barringford did the same. It was a long while,
and many startling things occurred, before they saw White Buffalo
again.
The thoughts of Rodney and his sister turned homeward now, and
both were anxious to see the old homestead once more. The twins
did not remember much, having been away so long, but they were
glad to get away from “the shooting Indians” as Artie called them.
It was a cold but clear day when the expedition reached Fort
Cumberland. Here the regulars reported, as they had been told to
do, and were properly discharged from further service in the army.
Rodney, Barringford, and the others also told their stories and
delivered a message sent by Colonel Bouquet, who was still near
Fort Pitt, trying to locate Pontiac.
All was now comparatively quiet around Fort Cumberland. To the
southward, a small band of Indians had appeared a few weeks
before and attacked some white and colored people, carrying two
colored girls, slaves of a Mr. Bowman, into captivity. To the
northward, the enemy had fallen on a band of Moravians while at
their devotions and slaughtered one of the leaders and two young
women. The Moravians were very bitter and wanted the English
army to drive the red men to the far west, beyond the Mississippi.
Leaving the others at Fort Cumberland, Rodney took the horses
and set off for the Morris homestead, in company with Barringford,
Nell, and the twins. The route was now familiar even to Nell, and
she watched eagerly for the first sign of the cabin.
“Papa! I see papa!” she cried, as they made a turn along the
brook road, and soon they saw Joseph Morris walking toward them,
rifle in hand, for none of the settlers thought of going out without
being armed.
“Rodney! and Nell!” burst from Joseph Morris’s lips, and he came
running up with a beaming face. He kissed his little daughter several
times. “Glad you are back! And you too, Sam,” he added to the old
frontiersman. “And how are the twins?” and he chucked them under
the chin.
“I am glad to be back,” said Rodney. “It seems like an age since I
went away and joined the soldiers.”
They did not stop to tell their story, for it was only a step more to
the log cabin. Mrs. Morris, the kindest of motherly women, came
rushing out of the door to greet them.
“Nell, my Nell!” she burst out, and hugged her daughter over and
over again, while the tears of joy streamed down her face. “Oh, how
glad I am that you are back!”
“And I am glad too, mamma,” said Nell. “Oh, it’s been such a very,
very long time since the Indians took me!”
“And Rodney!” went on Mrs. Morris, kissing his sunburnt cheek.
“How did you stand it? Didn’t the old lameness bother you?” And
then she hugged the twins and shook hands with Sam Barringford.
It was indeed a happy meeting all around.
“You must stay home, at least for the winter,” said Joseph Morris
to his son. “You have seen enough of peril for a time.”
“I am willing to stay home,” said Rodney. “But I think I ought to
join Uncle Jim and Dave and Henry in the spring.”
He told all the news that evening, sitting around the kitchen fire,
and Barringford and little Nell also told their tales. The old
frontiersman wanted to know if any letter had come from England
regarding the twins.
“Nothing as yet,” said Joseph Morris. “But it is something to know
that their father’s name is Maurice Hamilton, and that he is well-to-
do. Some day we shall probably hear from him.”
Much about the homestead had been destroyed by the Indians,
but Joseph Morris had worked hard to get things into shape again.
Family stores had been brought in, from Fort Cumberland and from
Annapolis, and the settler had cut a pile of wood for winter use.
“I hope all goes well with those left at Fort Pitt,” said Joseph
Morris. “It is said here that the Indians are very bitter out there.”
“They certainly are,” answered Rodney.
“It’s a pity Pontiac was not slain. He is the head and front of this
constant fighting. More than likely he will try to get up another
conspiracy before long.”
“Your neighbor, Jack Spader, just told me some news,” said Sam
Barringford, who sat on the doorstep, taking his ease in the
sunshine. “It is reported at Fort Cumberland that the Indians are
going to make another attack on Fort Pitt. Nobody seems to know
where the report started.”
“I trust it is not true,” replied Rodney.
“So do I,” added Mrs. Morris, “for the sake of Henry, and your
uncle, and Cousin Dave.”
“Well, they will have to do what they can to take care of
themselves,” said Joseph Morris. “Perhaps we shall have our own
hands full here this winter. The Indians have made no preparations
for cold weather, and rather than starve they may attack us.”