Don't forget to check wiki for detailed and updated documentations.
Features
To make the response dynamic, stubmatic comes with various features
Strategy: it helps to pick one file to serve the response.
Default mapping and short notations: Helps to keep mapping file as small as possible whitout verbosing same information
Multiple mapping files: Helps to keep the project organized.
Regular Expressions: You can use RE to match a request, capture some part of the request, to decide response file at runtime, to change contents of response at runtime etc. You can capture request part from URL, request body, headers, and query parameters.
Expressions: Stubmatic has support for inbuilt functions and markers to display date, random number etc.
Dumps: You can devide the response from multiple files to keep it simplified. And join them at runtime using dumps.
DB sets: Instead of creating multiple response files for each request, you can create response skeleton. Later you can fill data in this skeleton from dumps and data tables (DB sets).
Latency: You can set fix or random delay to serve the response
HTTPS: It supports HTTP and HTTPS both. You can set up 1 way and 2 way SSL hanshaking.
Attachments: You can write mapping to response a file.
Compression: If accept-encoding header is set to deflate or gzip then Stubmatic serves compressed response.
Configuration: If configuration file is missing, Stubmatic can build the response on the basis of directory structure.
Proxy: From 5.x onwards, you can also route requests to other servers..
Insepect HTTP requests: From 5.x onwards, You can inspect any HTTP request from CLI without setting up stubmatic repo..
Validator: You can validate XML, JSON, and YAML files from CLI that you mostly need to make stubs.
Other: There are also many other small features, like set response code, response headers, logging, debugging etc.
Other highlitghs
Memory and CPU efficient
Ready to be used in performance environment
No open bug
Who is using Stubmatic
There are more than 3000 people around the world who is using this tool. I'll update here with detail whoever would like to share the information.
Instructions
Writing stub for a SOAP webservice is pretty much same as writing stub for a POST HTTP call.
SOAP requests are in XML format and arrive to server as a part of HTTP request body. So if you know how to validate request body, you can easily write stubs for any SOAP webservice.
Let's take an example
Suppose the URL for a SOAP webservice is: "http://localhost:7777/services/Userdetails". And this is the sample request;
* If you see any error or red entry on screen Problem in loading mappings/response.yaml, it means there is some syntatical or space/indentation mistake.
Now Start the stubmatic server
$stubmatic -v
Configuration: {"mappings":{"default":{"request":{"method":"GET"},"response":{"strategy":"first-found","latency":0,"status":200}},"requests":["mappings/response.yaml"]},"server":{"port":7777,"host":"0.0.0.0"},"dbsets":"dbsets/","stubs":"stubs/","logs":{"path":"logs/"},"dumps":"dumps/"}
Loading 2 mappings from mappings/response.yaml
Loading DB from sampledb
Server listening on: http://0.0.0.0:7777
*-v is optional
Test it
You'll see following on the console.
97dda9950h POST: /services/Userdetails
Reading from file: stubs/response.xml
97dda9950h Response served in 144 ms with Status Code 200
Improvement
1. Capture some part of request
For simplification we have mapped only one request. We can add as many as we want. We can also use regular expressions. We can also specify the SOAP action in the mapping if "userId" can be repeated in multiple SOAP requests
To do this, let's create a db set(a text file which looks like a table) $vi dbsets/userdetails
id | name | dob | scenario
12345| Amit Gupta| {{formatDate(TODAY-30y,'dd-MM-YYYY')}} | > 30 years
23451| Deepika | {{formatDate(TODAY-26y,'dd-MM-YYYY')}} | < 30 years
* | Anamika | {{formatDate(TODAY-300y,'dd-MM-YYYY')}}| dead
Note
Scenario column is optional, I spcified just to remember why I did this entry
values in dob can be simple values. But I'm using expressions to make it dynamic.
Check the first example to setup the project. Here I'm explaining how to use Dumps to break large response file into chunks called dumps.
Dumps can be resued in multiple response file to maintain the consistency. And they can also be included conditionally using db sets.
For example: Including project 1,2,3 for one user while project 2,3,4,5 for other user. Check this good example to understand in detail.
Instructions
Check the first example to setup the project. Refer this sample maping to know what you can capture from request to match a mapping or to capture data from them.
You can capture or verify data from headers, query parameters, URL, cookies, and request body.
Check the first example to setup the project. Here I'm explaining how to proxy a request to other servers.
This feature can be used with various purpose. For example you want to stub few requests only, or to transfer the traffic to various other servers based on the URL, or using Stubmatic just to record or debug the HTTP requests, or to simulate 2G, 3G, 4G network conditions etc.