Package Exports
- stubby
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stubby) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Requirements
- node.js (tested with v0.6.x and v0.8.x)
Packaged
- coffee-script
- JS-YAML for loading yaml files
Optional (for debugging/testing)
Installation
via source
git clone git://github.com/Afmrak/stubby4node.git
cd stubby4node
cake build
via npm
npm install -g stubby
This will create the executable stubby
in the root level of the project.
Starting the Server(s)
Some systems require you to sudo
before running services on port certain ports (like 80)
[sudo] stubby
Command-line switches
stubby [-s <port>] [-a <port>] [-f <file>] [-l <hostname>] [-h] [-v]
-s, --stub [PORT] Port that stub portal should run on. Defaults to 8882
-a, --admin [PORT] Port that admin portal should run on. Defaults to 8889
-f, --file [FILE.{json|yml|yaml}] Data file to pre-load endoints.
-l, --location [HOSTNAME] Host at which to run stubby.
-h, --help This help text.
-v, --version Print stubby's version.
The Admin Portal
The admin portal is a RESTful(ish) endpoint running on localhost:8889
.
Supplying Endpoints to Stub
Submit POST
requests to localhost:8889
or load a file (-f) with the following structure:
request
: describes the client's call to the servermethod
: GET/POST/PUT/DELETE/etc.url
: the URI string. GET parameters should also be included inline hereheaders
: a key/value map of headers the server should respond topost
: a string matching the textual body of the response.
response
: describes the server's response to the clientheaders
: a key/value map of headers the server should use in it's responselatency
: the time in milliseconds the server should wait before responding. Useful for testing timeouts and latencybody
: the textual body of the server's response to the clientstatus
: the numerical HTTP status code (200 for OK, 404 for NOT FOUND, etc.)
YAML (file only)
- request:
url: /path/to/something
method: POST
headers:
authorization: "Basic usernamez:passwordinBase64"
post: this is some post data in textual format
response:
headers:
Content-Type: application/json
latency: 1000
status: 200
body: You're request was successfully processed!
- request:
url: /path/to/anotherThing?a=anything&b=more
method: GET
headers:
Content-Type: application/json
post:
response:
headers:
Content-Type: application/json
Access-Control-Allow-Origin: "*"
status: 204
body:
- request:
url: /path/to/thing
method: POST
headers:
Content-Type: application/json
post: this is some post data in textual format
response:
headers:
Content-Type: application/json
status: 304
body:
JSON (file or POST/PUT)
[
{
"request": {
"url": "/path/to/something",
"post": "this is some post data in textual format",
"headers": {
"authorization": "Basic usernamez:passwordinBase64"
},
"method": "POST"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"latency": 1000,
"body": "You're request was successfully processed!"
}
},
{
"request": {
"url": "/path/to/anotherThing?a=anything&b=more",
"headers": {
"Content-Type": "application/json"
},
"post": null,
"method": "GET"
},
"response": {
"status": 204,
"headers": {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
},
"body": null
}
},
{
"request": {
"url": "/path/to/thing",
"headers": {
"Content-Type": "application/json"
},
"post": "this is some post data in textual format",
"method": "POST"
},
"response": {
"status": 304,
"headers": {
"Content-Type": "application/json"
},
"body": null
}
}
]
If you want to load more than one endpoint via file, use either a JSON array or YAML list (-) syntax. On success, the response will contain Content-Location
in the header with the newly created resources' location
Getting the Current List of Stubbed Responses
Performing a GET
request on localhost:8889
will return a JSON array of all currently saved responses. It will reply with 204 : No Content
if there are none saved.
Performing a GET
request on localhost:8889/<id>
will return the JSON object representing the response with the supplied id.
Change existing responses
Perform PUT
requests in the same format as using POST
, only this time supply the id in the path. For instance, to update the response with id 4 you would PUT
to localhost:8889/4
.
Deleting responses
Send a DELETE
request to localhost:8889/<id>
The Stub Portal
Requests sent to any url at localhost
or localhost:8882
will search through the available endpoints and, if a match is found, respond with that endpoint's response
data
Running tests
If you don't have jasmine-node already, install it:
npm install -g jasmine-node
From the root directory run:
jasmine-node --coffee spec
See Also
stubby4j: A java implementation of stubby
TODO
PUT
ing multiple responses at a time.- SOAP request/response compliance
- Dynamic port switching
- HTTP/SSL auth mocking
- Randomized responses based on supplied pattern (exploratory QA abuse)
NOTES
- Copyright 2012 Eric Mrak, Alexander Zagniotov, Isa Goksu
- License Apache v2.0