Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Aug 29, 2017
2 parents b6ebce9 + d8d943e commit 4ca8211
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 23 additions & 8 deletions doc/readme-ui-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@

The mock server UI is available at _http://localhost:3003_ (or at the port you have defined via options).

If the service you want to mock provides a Swagger definition and you have provided a swagger definition, you may perform an import via the small triangle button in the head of the UI page.
If the service you want to mock provides a Swagger definition and you have provided a [`swaggerImport` configuration item](https://github.com/smollweide/node-mock-server/blob/c52adcf2a80999dd6876062006cf72c1ef124a78/demo/index.js#L41-L53), you may perform a Swagger import via the small triangle button in the top right of the UI page.

In the same location you also find general preferences such as a response delay and you can trigger a validation of all responses.
In the same location you find general preferences such as a response delay and you can trigger a validation of all responses.

In addition to Swagger imports, you may also [define a resource path with a ReST method folder containing a mock directory](https://github.com/smollweide/node-mock-server/blob/master/doc/readme-folder-structure.md) manually by creating the appropriate folders in the file system. Once a resource has been defined that way, you can continue to work with the resource in the UI. Refresh the browser to see new resources after you have added them in the file system.
In addition to Swagger imports, you may create resources manually using the **+add new endpoint** button at the bottom of the mock server UI page. You will be asked to enter a path, a http method and a description. The path must always begin with a slash and a path segment denoting the base url of the api. After the base url you can enter a sequence of more path segments separated by /. If path segments should be variables, use a parameter name in curly braces:

The UI shows you a list of known resources. Alongside each resource there are buttons which allow you to work with the responses for that method.
/users points to the users api base url
/users/{userid}/address contains a path variable userid

Click the button for a ReST method (e.g. GET) to define possible responses for that method. A popup appears that shows the possible responses and allows to add new responses. Initially there are no `success` and `error` responses defined, therefore you only see a `middleware` response. The node-mock-server can respond through a [middleware definition](https://github.com/smollweide/node-mock-server/blob/master/doc/readme-middleware.md), so *middleware* is always available.
Once a resource has been defined that way, you can continue to work with the resource and edit the possible responses.

Hit *+Add* to add a new response and call it `success`. Your favorite JSON editor is fired up where you can enter the response. It will be stored as _success.json_ inside the _mock_ directory.
The UI shows you a list of known resources. Alongside each resource there are buttons which allow you to work with the responses for that method.

Click the button for a ReST method (e.g. GET) to define possible responses for that method. A popup appears that shows the known responses and allows to add new responses. A newly created resource always has a set of default responses:

* empty.json
* error.json
* success.json
* middleware

Initially, empty.json, error.json and success.json contain an empty object as response. Click **open** to fill in the required response data.
The node-mock-server can also respond through a [middleware definition](https://github.com/smollweide/node-mock-server/blob/master/doc/readme-middleware.md); therefore you cannot edit a json file for it.

To enter a new response, hit *+add new response* to add a new response, e.g. `foo.json`. Your favorite text editor is fired up where you can enter the response. It will be stored as _foo.json_ inside the _mock_ directory.

For an error response the default HTTP status code is 500, but you can specify a different status code by suffixing the name of your error response with the appropriate status code, like `error-423.json`.

After storing the response you can select the radiobutton in front of your new response. A file _response.txt_ will be created alongside your possible responses, which stores your decision. All decisions can be captured, restored, reset and shared by means of a [collection](https://github.com/smollweide/node-mock-server/blob/master/doc/readme-collections.md).

After storing the response you can select the radiobutton in front of your new `success` response. A file _response.txt_ will be created alongside your possible responses, which stores your decision. All decisions can be captured, restored, reset and shared by means of a [collection](https://github.com/smollweide/node-mock-server/blob/master/doc/readme-collections.md).

You can also add an `error` response and use the radiobutton in front of it to specify that the resource should respond with an error response. For an error response the default HTTP status code is 500, but you can specify a different status code by suffixing the name of your error response with the appropriate status code, like error-401.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-mock-server",
"version": "0.18.0-alpha-3",
"version": "0.18.1",
"description": "File based Node REST API mock server",
"email": "[email protected]",
"author": "Simon Mollweide <[email protected]>",
Expand Down

0 comments on commit 4ca8211

Please sign in to comment.