All Projects → knuton → Stubb

knuton / Stubb

Licence: mit
Specify REST API stubs using your file system.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Stubb

Fakerest
Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
Stars: ✭ 350 (+21.11%)
Mutual labels:  rest, test
Rest Assured
Java DSL for easy testing of REST services
Stars: ✭ 5,646 (+1853.63%)
Mutual labels:  rest, test
Chakram
REST API test framework. BDD and exploits promises
Stars: ✭ 912 (+215.57%)
Mutual labels:  rest, test
Vscode Restclient
REST Client Extension for Visual Studio Code
Stars: ✭ 3,289 (+1038.06%)
Mutual labels:  rest
Presentations
Collection of presentations for advanced Python topics
Stars: ✭ 264 (-8.65%)
Mutual labels:  rest
Product Ei
An open source, a high-performance hybrid integration platform that allows developers quick integration with any application, data, or system.
Stars: ✭ 277 (-4.15%)
Mutual labels:  rest
Bazel
a fast, scalable, multi-language and extensible build system
Stars: ✭ 17,790 (+6055.71%)
Mutual labels:  test
Reservoir
A back end for your front end: a content repository. Powered by Drupal 8, JSON API and OAuth2.
Stars: ✭ 262 (-9.34%)
Mutual labels:  rest
Fishtape
100% pure-Fish test runner.
Stars: ✭ 283 (-2.08%)
Mutual labels:  test
Selenium Document
a document with regard to selenium
Stars: ✭ 274 (-5.19%)
Mutual labels:  test
Requester
Powerful, modern HTTP/REST client built on top of the Requests library
Stars: ✭ 273 (-5.54%)
Mutual labels:  rest
Mars
MARS-Curiosity Delphi REST Library
Stars: ✭ 268 (-7.27%)
Mutual labels:  rest
Aioresponses
Aioresponses is a helper for mock/fake web requests in python aiohttp package.
Stars: ✭ 278 (-3.81%)
Mutual labels:  test
Shrine
File Attachment toolkit for Ruby applications
Stars: ✭ 2,903 (+904.5%)
Mutual labels:  rack
Nodejs Restful Api
How to create a RESTful CRUD API using Nodejs?
Stars: ✭ 285 (-1.38%)
Mutual labels:  rest
Flutter Redux Starter
Starter project and code generator for Flutter/Redux
Stars: ✭ 262 (-9.34%)
Mutual labels:  rest
Jsonld
JSON-LD processor for PHP
Stars: ✭ 280 (-3.11%)
Mutual labels:  rest
Secure headers
Manages application of security headers with many safe defaults
Stars: ✭ 2,942 (+917.99%)
Mutual labels:  rack
Goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
Stars: ✭ 2,943 (+918.34%)
Mutual labels:  test
Minitest
minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.
Stars: ✭ 2,962 (+924.91%)
Mutual labels:  test

Stubb

Stubb is a testing and development tool for frontend developers and anyone else depending on HTTP-requesting resources for their work. It allows setting up a REST API stub by putting responses in files organized in a directory tree. Which file is picked in response to a particular HTTP request is primarily determined by the request's method, path and accept header. Thus adding a response for a certain type of request is as easy as adding a file with a matching name. For example, the file

whales/narwhal.GET.json

in your base directory will be picked to deliver the response to the request

GET /whales/narwhal.json HTTP/1.1

or alternatively

GET /whales/narwhal HTTP/1.1
Accept: application/json

.

Additionally, sequences of responses to repeated identical requests can be defined through infix numerals in file names.

Getting Started

Simply install the Stubb gem by running

gem install stubb

and you are ready to run the stubb CLI:

$ stubb
Tasks:
  stubb help [TASK]  # Describe available tasks or one specific task
  stubb server       # Starts the server
  stubb version      # Print the version of Stubb

$ echo Ahoy > hello-world.GET
$ ls
hello-world.GET
$ stubb server &
$ curl http://localhost:4040/hello-world
Ahoy

By default the server runs on port 4040 and looks for response files in the working directory. Run stubb help server for information on configuration options.

Directory Structure and Response Files

All requests are served from the base directory, that is the directory Stubb was started from. The directory tree in your base directory determines the path hierarchy of your stubbed REST API. Request paths are mapped to relative paths within the base directory to locate a response file.

Response Files

A response file is a file containing an API response. There are two kinds of response files, member response files and collection response files. They differ only in concept and naming.

Member Response Files

A member response file is a file containing an API response for a member resource, named after the scheme

REQUEST_PATH_WITHOUT_EXTENSION.HTTP_METHOD[.SEQUENCE_NUMBER][.FILE_TYPE]

, where SEQUENCE_NUMBER is optional and only needed when defining response sequences, and FILE_TYPE is also optional and only needed when a file type is implied by request path or accept header.

Examples:

whales/narwhal.GET
whales/narwhal.GET.json
whales/narwhal.GET.1
whales/narwhal.GET.1.json

Collection Response Files

A collection response file is a file containing an API response for a collection resource, named after the scheme

REQUEST_PATH_WITHOUT_EXTENSION/HTTP_METHOD[.SEQUENCE_NUMBER][.FILE_TYPE]

, where SEQUENCE_NUMBER is optional and only needed when defining response sequences, and FILE_TYPE is also optional and only needed when a file type is implied by request path or accept header.

Examples:

whales/GET
whales/GET.json
whales/GET.1
whales/GET.1.json

Response Files as ERB Templates

Any matching response file will be evaluated as an ERB template, with GET or POST parameters available in a params hash. This can come in handy when stubbing POST and PUT requests or serving JSONP.

YAML Frontmatter

Response files may contain YAML frontmatter before the response text, allowing to set custom values for response status and header:

---
status: 201
header:
  Cache-Control: no-cache
---
{"name":"Stubb"}

Missing Responses

If no matching response file is found, Stubb replies with a status of 404. You can customize error responses for types of requests by creating a matching response file that contains your custom response.

Path Matching

Paths in the base directory may include wildcards to allow one response file to match for a whole range of request paths instead of just one. Both Directory names and file names may be wildcards. Wildcards are marked by starting and ending in an underscore (_). A wildcard segment matches any equally positioned segment of a request path.

For example

whales/_default_whale_.GET.json

matches

GET /whales/pygmy_sperm_whale.json HTTP/1.1

as well as

GET /whales/blackfish.json HTTP/1.1

.

If a literal match exists, it will be chosen over a wildcard match.

Response Sequences

A response sequence is a sequence of response files whose members are being used as responses to a sequence of requests of the same type. This allows for controlled stubbing of changes in the API.

Stalling Sequences (1...n)

A stalling sequence keeps responding with the last response file in the response sequence after n requests of the same type. Stalling sequences are specified by adding response files with indices 1 through n.

GET.1.format, GET.2.format, ..., GET._n-1_.format, GET._n_.format

Example:

whales/GET.1.json
whales/GET.2.json
whales/GET.3.json

From the third request on, the response to

GET /whales.json HTTP/1.1

will be the one given in whales/GET.3.json.

Looping Sequences (0...n-1)

A looping sequence starts from the first response file in the response sequence after n requests of the same type. Looping sequences are specified by adding response files with indices 0 through n-1.

GET.0.format, GET.1.format, ..., GET._n-2_.format, GET._n-1_.format

Example:

whales/GET.0.json
whales/GET.1.json
whales/GET.2.json

The response to the fourth request to

GET /whales.json HTTP/1.1

will again be the one given in whales/GET.0.json, and so forth.

Dependencies

Stubb depends on

  • Rack for processing and serving requests, and
  • Thor for adding a CLI executable.

Acknowledgements

The logo for Stubb was kindly provided by Andres Colmenares of Wawawiwa.

License

Copyright (c) 2011 Johannes Emerich

MIT-style licensing, for details see file LICENSE.


Build Status

'Why,' thinks I, 'what's the row? It's not a real leg, only a false leg.'
--Stubb in Moby Dick

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].