A minimal app to illustrate the usage and testing of middleware.
- Basic Rack App
- Quote Retriever
- Quick Formatter
When a request is made at any URI other than /quote
, the response is as follows. Passing parameters along with the request (GET
/POST
) does not affect the response.
Request: /<any path>
Response: 'Just some regular text here.'
Format: text/plain
This is a piece of middleware. When a request is made at /quote
, the response is as follows. Passing parameters of the form { 'term' => <keyword> }
along with a request (GET
/POST
) narrows down the possibilities of the random quote returned, through substring matching. If no matches are found, a message is displayed instead of the quote: 'No quotes found. Try again!'
Request: /quote
Response: <random quote>
Format: text/plain
As an exercise to illustrate the ordering of middleware and how different layers stack, this is another piece that wraps a simple html frame around the response, if the original response is text/plain
. This can be turned off in config.ru
by removing the true
argument on the use QuickFormatter
line.
Request: /<any path>
Response: html page
Format: text/html
RSpec tests are written for the QuoteRetriever middleware. Tests for POST
requests are also written, and are virtually identical to the tests for GET
requests. These can all be run by executing the following command:
$ rspec spec