{"id":18724344,"url":"https://github.com/mock-server/mockserver-client-node","last_synced_at":"2025-12-12T03:45:15.063Z","repository":{"id":22518438,"uuid":"25858869","full_name":"mock-server/mockserver-client-node","owner":"mock-server","description":"MockServer javascript client for browsers, Node.js or any grunt build","archived":false,"fork":false,"pushed_at":"2024-09-06T05:31:39.000Z","size":3446,"stargazers_count":73,"open_issues_count":20,"forks_count":34,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T15:13:26.974Z","etag":null,"topics":["grunt-plugin","java-client","javascript-client","mock-server","node-client","node-module","proxy","ruby-client"],"latest_commit_sha":null,"homepage":"http://mock-server.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mock-server.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-28T08:02:58.000Z","updated_at":"2024-12-22T18:57:00.000Z","dependencies_parsed_at":"2024-06-03T18:53:58.711Z","dependency_job_id":"722e544b-2579-47eb-9aea-469283165730","html_url":"https://github.com/mock-server/mockserver-client-node","commit_stats":{"total_commits":285,"total_committers":20,"mean_commits":14.25,"dds":0.6491228070175439,"last_synced_commit":"8035b2a30ba431ba59b6d182d602c97f3a588aca"},"previous_names":["jamesdbloom/mockserver-client-node"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mock-server%2Fmockserver-client-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mock-server%2Fmockserver-client-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mock-server%2Fmockserver-client-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mock-server%2Fmockserver-client-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mock-server","download_url":"https://codeload.github.com/mock-server/mockserver-client-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299831,"owners_count":20916190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grunt-plugin","java-client","javascript-client","mock-server","node-client","node-module","proxy","ruby-client"],"created_at":"2024-11-07T14:06:09.942Z","updated_at":"2025-12-12T03:45:15.006Z","avatar_url":"https://github.com/mock-server.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mockserver-client-node \n\n\u003e Communicate with a [MockServer](http://mock-server.com/) from any node or grunt build\n\n[![Build status](https://badge.buildkite.com/368c3b69e959f29725d8ab582f8d75dedddceee196d39b6d28.svg?style=square\u0026theme=slack)](https://buildkite.com/mockserver/mockserver-client-node) [![Dependency Status](https://david-dm.org/mock-server/mockserver-client-node.png)](https://david-dm.org/mock-server/mockserver-client-node) [![devDependency Status](https://david-dm.org/mock-server/mockserver-client-node/dev-status.png)](https://david-dm.org/mock-server/mockserver-client-node#info=devDependencies)\n\n[![NPM](https://nodei.co/npm/mockserver-client.png?downloads=true\u0026stars=true)](https://nodei.co/npm/mockserver-client/) \n\n# Community\n\n* Backlog:\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003ca href=\"https://trello.com/b/dsfTCP46/mockserver\" target=\"_blank\"\u003e\u003cimg height=\"20px\" src=\"http://mock-server.com/images/trello_badge-md.png\" alt=\"Trello Backlog\"\u003e\u003c/a\u003e\n* Freature Requests:\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/mock-server/mockserver/issues\"\u003e\u003cimg height=\"20px\" src=\"http://mock-server.com/images/GitHub_Logo-md.png\" alt=\"Github Issues\"\u003e\u003c/a\u003e\n* Issues / Bugs:\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003ca href=\"https://github.com/mock-server/mockserver/issues\"\u003e\u003cimg height=\"20px\" src=\"http://mock-server.com/images/GitHub_Logo-md.png\" alt=\"Github Issues\"\u003e\u003c/a\u003e\n* Chat:\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003ca href=\"https://join-mock-server-slack.herokuapp.com\" target=\"_blank\"\u003e\u003cimg height=\"20px\" src=\"http://mock-server.com/images/slack-logo-slim-md.png\" alt=\"Join Slack\"\u003e\u003c/a\u003e\n\n## Getting Started\n\n[MockServer](http://mock-server.com/) allows you to mock any system you integrate with via HTTP or HTTPS (i.e. (REST) services, web sites, etc). Please note that it is a third party project that needs java.\n\nThis npm module allows any grunt or node project to easily communicate with a running [MockServer](http://mock-server.com/) instance.\n\nAs an addition to this module for communicating with a running MockServer there is a second project that can be used to start and stop a MockServer called [mockserver-node](https://www.npmjs.org/package/mockserver-node).\n\nThe MockServer client can be created as follows:\n\n```js\nvar mockServer = require('mockserver-client'),\n    mockServerClient = mockServer.mockServerClient // MockServer and proxy client\n```\n**Note:** this assumes you have an instance of MockServer running on port 1080.\nFor more information on how to do so check [mockserver-node](https://www.npmjs.org/package/mockserver-node).\n\n## Setup Expectation\n\nA simple expectation can be set up as follows:\n\n```js\nmockServerClient(\"localhost\", 1080)\n    .mockSimpleResponse('/somePath', { name: 'value' }, 203)\n    .then(\n        function(result) {\n            // do something next\n        }, \n        function(error) {\n            // handle error\n        }\n    );\n```\n\nA more complex expectation can be set up like this:\n\n```js\nmockServerClient(\"localhost\", 1080)\n    .mockAnyResponse(\n        {\n            'httpRequest': {\n                'method': 'POST',\n                'path': '/somePath',\n                'queryStringParameters': [\n                    {\n                        'name': 'test',\n                        'values': [ 'true' ]\n                    }\n                ],\n                'body': {\n                    'type': \"STRING\",\n                    'value': 'someBody'\n                }\n            },\n            'httpResponse': {\n                'statusCode': 200,\n                'body': JSON.stringify({ name: 'value' }),\n                'delay': {\n                    'timeUnit': 'MILLISECONDS',\n                    'value': 250\n                }\n            },\n            'times': {\n                'remainingTimes': 1,\n                'unlimited': false\n            }\n        }\n    )\n    .then(\n        function(result) {\n            // do something next\n        }, \n        function(error) {\n            // handle error\n        }\n    );\n```\n\nFor the full documentation see [MockServer - Creating Expectations](https://mock-server.com/mock_server/creating_expectations.html).\n\n## Verify Requests\n\nIt is also possible to verify that request were made:\n\n```js\nmockServerClient(\"localhost\", 1080)\n    .verify(\n        {\n            'method': 'POST',\n            'path': '/somePath',\n            'body': 'someBody'\n        }, \n        1, true\n    )\n    .then(\n        function() {\n            // do something next\n        }, \n        function(failure) {\n            // handle verification failure\n        }\n    );\n```\nIt is furthermore possible to verify that sequences of requests were made in a specific order:\n\n```js\nmockServerClient(\"localhost\", 1080)\n    .verifySequence(\n        {\n            'method': 'POST',\n            'path': '/somePathOne',\n            'body': 'someBody'\n        },\n        {\n            'method': 'GET',\n            'path': '/somePathTwo'\n        },\n        {\n            'method': 'GET',\n            'path': '/somePathThree'\n        }\n    )\n    .then(\n        function() {\n            // do something next\n        }, \n        function(failure) {\n            // handle verification failure\n        }\n    );\n```\n\nFor the full documentation see [MockServer - Verifying Requests](https://mock-server.com/mock_server/verification.html).\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Changelog\n\nAll notable and significant changes are detailed in the [MockServer changelog](https://github.com/mock-server/mockserver/blob/master/changelog.md) \n\n---\n\nTask submitted by [James D Bloom](http://blog.jamesdbloom.com)\n\n[![Analytics](https://ga-beacon.appspot.com/UA-32687194-4/mockserver-client-node/README.md)](https://github.com/igrigorik/ga-beacon)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmock-server%2Fmockserver-client-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmock-server%2Fmockserver-client-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmock-server%2Fmockserver-client-node/lists"}