{"id":13493285,"url":"https://github.com/mvemjsun/mock_server","last_synced_at":"2026-01-27T11:38:10.320Z","repository":{"id":48097236,"uuid":"53263798","full_name":"mvemjsun/mock_server","owner":"mvemjsun","description":"A lightweight Sinatra application backed by sqlite that can mock ReST responses. Has interface to easily create, search \u0026 maintain mocks. No need to program mocks into a language specific implementation.","archived":false,"fork":false,"pushed_at":"2024-03-23T20:39:31.000Z","size":6353,"stargazers_count":110,"open_issues_count":2,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T11:39:55.102Z","etag":null,"topics":["mock-server","ruby","sinatra"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mvemjsun.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":"2016-03-06T16:14:41.000Z","updated_at":"2024-03-25T13:11:14.000Z","dependencies_parsed_at":"2024-10-31T07:31:29.256Z","dependency_job_id":"abd8839f-0144-4e7b-a3bc-c3a8b7659bc3","html_url":"https://github.com/mvemjsun/mock_server","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mvemjsun/mock_server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvemjsun%2Fmock_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvemjsun%2Fmock_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvemjsun%2Fmock_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvemjsun%2Fmock_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mvemjsun","download_url":"https://codeload.github.com/mvemjsun/mock_server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvemjsun%2Fmock_server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28812498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T07:41:26.337Z","status":"ssl_error","status_checked_at":"2026-01-27T07:41:08.776Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["mock-server","ruby","sinatra"],"created_at":"2024-07-31T19:01:13.839Z","updated_at":"2026-01-27T11:38:10.303Z","avatar_url":"https://github.com/mvemjsun.png","language":"Ruby","readme":"## Mocking Bird\n\u003e An easy way to setup mock responses by specifying mock URL, HTTP verb, Response headers and Response body. \n\n![](https://github.com/mvemjsun/mock_server/blob/master/public/img/architecture.png?raw=true)\n\n### Quick Start\n\nEnsure ruby and `bundler` are installed. RVM is a good way to manage rubies on your machine.\n\n- git clone `https://github.com/mvemjsun/mock_server.git`\n- Run `bundle install --without=test pg`\n- There is an starter mock database inside the `/db` folder, you can use it to get started.\n- The sample db has one mocked url that serves a test url `/ping`.\n- Run `sh ./start-mock.sh` from the project root which starts the server on port 9292.\n- Visit `http://localhost:9292/mock/search` and search. To see the available mocks.\n- Visit `http://localhost:9292/mock/create` and create your mocks.\n- Direct your API requests to the mock server and have them served.\n\nNote: \n- To create a new mock db navigate to `/db` folder and delete the supplied sqlite db (`mockserver.db` file).\n- Run `rake db:migrate` from the project root. This will create an emty database file with no mocks.\n\n### Summary\n\nThe core idea behind this tool is having the ability to quickly and easily create mock responses for URLs that respond to HTTP verbs. It can help to\n test client devices against a mock server both manually and by using automated tests. All this is \nachieved by an easy to use user interface that allows a user to specify a URL to mock, set the return HTTP status, headers and last \nbut not the least the response body. Mocking bird is slightly different from conventional mocking frameworks in that most of its features can be used even by\nnon-programmers who have got a basic knowledge of HTTP structure (headers, status codes \u0026 body); **also mocks need not be programmed into a language specific implementation. \nSet up once and use across multiple clients that use differing technologies.** \n\nThe requests to the mock server can also be logged into the mock database if the environment variable `REQUEST_LOGGING` has been defined. \nThe logs can also be cleared using an api call (see API support section below)\n\nImages can be served using custom urls defined withing the mock server. Facility to upload the images is also\nprovided. Mocking can becomes super easy if there are existing API endpoints that return data, existing API responses be cloned via the GET button on the home \npage and then modified (currently only GET requests are supported).\n\nThe cloning feature can be used if there is existing data available that can be retrieved via HTTP GET requests, this can be quickly cloned into\nthe mock database and then modified.\n\nThe Implementation has been experimented and tested on OSX 10.10 and 10.11. User interface has been driven using recent versions of Safari (9.1) and Chrome (49.0).\n\nThe tool has been kept lightweight so that it can be installed and run on a developers/testers machine easily and quickly without any major software\nor memory requirements.\n\n\n### Features\n\nThe tool can be used either as a standalone mock server on an individuals PC or setup as a team mock server. Its upto the team and user(s) to\ndecide what suits their needs.\n\n#### Create Mock\n\nCreate a mock by supplying relevant details on the form on the Home page. URL responses can be cloned if they require no \\\nclient configuration.\n\n#### Search Mock\nNavigate to the search option and supply part of the mock name to search.\n\n#### Update Mock\nEdit an existing mock (search for it first).\n\n#### Clone in batch\nIf you have a set of Rest URL's that require no client configuration. Then you can clone the URLs into the mock database using the \nbatch clone option.\n\n#### Replace Data\nReplace data can be created to look for 'replace strings' either by exact match or by regular expressions. This is a final\npoint in the request response time-line where the mock response that have been setup can still be modified before the\nresponse is sent back to the client. Replace data can be applied only to the response body. For example there could be\na mock that has been set up to return the personal details of the user as\n\n```\n{\n    \"name\" : \"John\",\n    \"middleName\" : \"Smith\",\n    \"dob\" : \"1975-09-11\",\n    \"postCode\" : \"TF12 6TR\"\n}\n```\n\nWe could set up a replace data(s) so that the string `\"dob\" : \"1975-09-11\"` is replaced by `\"dob\" : \"1955-01-11\"`.\n\n#### Upload Images\nImages can be uploaded in case you want to mock url's that end with image names.\n\n### Possible use cases\n\n#### No existing data available\n   Visit the /mock/create and create mock responses by entering response details manually\n   \n#### Existing data available\n   This option could be used when minimal test data is available. We have two ways to mock here.\n   * Visit the /mock/create page and clone an individual request into the mock database via the GET button (Menu - Home)\n   * If you have a set of URL's to hand that return data then use them to clone in batch using the /mock/clone/batch (Menu - Clone Many). This\n     option will clone the data into the database that you can then edit search followed by selecting a result and editing it.\n\n#### Images\n   * Images can be served if they are placed in /public/img directory and then the urls point to it like `http://xx.xx.xx.xx/img/captcha.png` \n     where `xx.xx.xx.xx` is the ip address of the mock server.\n     \n   * To serve custom image URLs, first upload the image onto the mock server and then create a mock URL with correct content type (png or jpeg)\n     . The Image file name at the end of the url must match the uploaded image name (case sensitive). For example if you want to serve the URL\n     `get/me/a/cat.png` then upload the image with name `cat.png` while creating the mock URL. Note only urls that end with an image file name\n     can be served.\n\n### Wildcard in routes (experimental)\n   * If a mock url is set up with a wildcard character `*` in it then the mock server will attempt to match against the \"wild\" route if no exact match is found. For example if a mock URL\n   is set up as `/say/(.*)/to/(.*)` then this will match `/say/hello/to/tom` or `/say/hola/to/rafael`.\n   \n   * Similarly if a mock URL is set up as `/get/me/item/(.*)` will match `/get/me/item/2345`. \n   \n   When specifying wildcard in routes please ensure that any characters in the url that have a special meaning to the regex engine are escaped.\n   For example if the url is `/get/me/a/book?id=98765` then you could have a wildcard route as `/get/me/a/book\\?id=(.*)`.\n    \n### Basic Cookie support\n   Mocks can be set up to return cookies. The cookie details should be entered ONE cookie in each line. The format is `cookieName cookieValue`.\n   The cookie name should be followed by a space. If multiple cookies are required then enter each in its own line followed by a line-break.\n   \n   ```ruby\n     userId 987656789\n     token 7yser345abnjdlo12469sdfqws\n     ssd yef32lvcdds\n   ```\n   The above will return 3 cookies with names userId, token and ssd with above values.\n\n### Scripting Support (Experimental)\n   A mock url can optionally be set up with scripting support. The scripts have to be written in Ruby. The mock responses\n    specify the name of the before and after scripts when they are being created/updated. These scripts should have been\n    created using the scripts option from the menu. The script names should be one or more scripts names ending `.rb`\n    delimited by a `,` (comma) character.\n    \n   The scripts are evaluated with the `before` and `after` Sinatra filters and are evaluated in the context of  Sinatra\n    request and responses. The scripts can for example be used to set up headers that need to be generated at run time or\n    manipulate the response body before its sent back to the client.\n    \n   A word of CAUTION - Scripts are evaluated using ruby `eval` statement without any checks, so use them with caution.\n    \n   The mock_response build from the mock database is available in the instance variable `@mock_response`. \n    Example script that adds a custom header `X-AfterScript-Time` and sets the response body could be set as\n    \n   ```ruby\n    headers({\"X-AfterScript-Time\" =\u003e \"#{Time.now}\"})\n    @mock_response[:mock_data_response] = 'Hi Ya how are you'\n    body @mock_response[:mock_data_response]\n   ```\n    \n   This uses the Sinatra's functions `headers` and passes it a header hash. Similarly the `body` function is used to set\n    an altered body.\n\n### API support\n   * Mockdata in the database can be activated or deactivated using its id.\n   \n   ```\n      # To activate a mock url with Id = 1\n      # http://localhost:9292/mock/api/activate/1      \n      # To deactivate a mock url with id = 1\n      # http://localhost:9292/mock/api/deactivate/1\n   ```\n   Note that activating a url will deactivate any active form of that url in that test environment.\n   \n   * Latency of responses can be set using\n   ```\n   http://localhost:9292/latency/1 \n   OR\n   http://localhost:9292/latency/3\n   ```\n   This sets the global latency to 1 or 3 seconds for ALL mock responses. Please note that due to the blocking nature of the latency implementation\n   at the moment, all server processing will be blocked while the latency is processed. The default latency is 0.\n   \n   To set the latency back to 0 issue the call `http://localhost:9292/latency/0`\n   \n   To set latency for individual url's you will have to use the 'Advanced options' and mention the name of a ruby script \n   with a sleep statement in it. So for example\n   you could have `sleep1.rb` to `sleep5.rb` with `sleep n` statements in them (where `n` is from 1 to 5) to cause an\n   artificial delay in the response.\n   \n   * Replace data rows in the DB can be activated using the endpoint\n   \n   The below will activate \u0026 decativate the replace data row with an id of 1. Any other rows that have the same replace string will be deactivated\n   ```\n   http://localhost:9292/mock/api/replace_data/activate/1\n   http://localhost:9292/mock/api/replace_data/deactivate/1\n   ```\n   \n   * Reset mock url's served count. The below url will set the served counts to 0 for all the mock urls in the database. This could be ideally be done at the start of a test.\n   \n   ```\n   http://localhost:9292/mock/api/reset\n   ```\n   \n   * Retrieve recent data from `httpRequestLog` table\n   ```\n   http://localhost:9292/mock/api/requestlog/recent\n   ```\n   \n   * Retrieve `httpRequestLog` table data within a time range\n   ```\n   http://localhost:9292/mock/api/requestlog/range?from=2016-09-11 16:31:00\u0026to=2016-09-11 16:32:11[\u0026matching=\u003cmatchingString\u003e]\n   ```\n   matching query parameter is optional, could have a value like `matching=/account`\n   \n   * Delete all data from the `httpRequestLog` table\n   ```\n   http://localhost:9292/mock/api/reset/requestlog\n   ```\n   \n   * Update all rows in the Replacedata table \n   ```\n   http://localhost:9292/mock/api/update/replacedata?string=xxx\u0026with=yyy\n   ```\n   \n   | API | Type |Description |\n   | --- | --- | --- |\n   | http://localhost:9292/mock/api/activate/1 | POST | Activate mock with id 1 |\n   | http://localhost:9292/mock/api/deactivate/1  | POST | Deactivate mock with id 1 |\n   | http://localhost:9292/latency/1  | POST | Set latency of response to 1 second |\n   | http://localhost:9292/latency/2  | POST | Set latency of response to 2 seconds |\n   | http://localhost:9292/mock/api/replace_data/activate/1 | POST | Set replace data mock 1 to active |\n   | http://localhost:9292/mock/api/replace_data/deactivate/1 | POST | Set replace data mock 1 to Inactive |\n   | http://localhost:9292/mock/api/reset | POST | Reset served counts for all the URLs to 0 |\n   | http://localhost:9292/mock/api/requestlog/recent | GET | Return the recent logged requests |\n   | http://localhost:9292/mock/api/requestlog/range?from=2016-09-11 16:31:00\u0026to=2016-09-11 16:32:11[\u0026matching=\u003cmatchingString\u003e] | GET | Get recent log for a time range|\n   | http://localhost:9292/mock/api/reset/requestlog | POST | Delete the request logs |\n   | http://localhost:9292/mock/api/update/replacedata?string=xxx\u0026with=yyy | POST | Update the replace data string to be replaced |\n   \n### Request log console\n   The `Live Requests` tab on the web interface shows the requests being served by the mock server.\n   ![](https://github.com/mvemjsun/mock_server/blob/master/public/img/request_logs.png?raw=true)\n   \n### Tests \n   \n   There is some coverage for the main features of the mock server around creating mocks and search. The tests are run using `RSpec` \u0026 `Capybara` webkit driver.\n   To run the tests ensure that you set the environment variable `ENVIRONMENT` and set it to `test`. Run the rake migration to create the test database using\n   the command `ENVIRONMENT='test' rake db:migrate`. Then start the mock server using `ENVIRONMENT='test' sh ./start-mock.sh` from the project root.\n   \n   The tests can then be run using the command `rspec` from the project root.\n\n### Data migration\n   You could potentially experiment using the mock server using sqlite and if there is a need you could migrate data \n   from sqlite to another RDBMS such as Postgres. To do this you need to have the new DB already installed. \n   The `database.yml` should contain the setup info for it such as\n   \n   ```\n   development_pg:\n     adapter: postgresql\n     encoding: unicode\n     database: postgres\n     pool: 5\n     username: postgres\n     password: postgres\n     host: localhost\n   ```\n     \n   Which points to a database named `postgres`. Run the rake task `rake db:migrate` with environment variable `ENVIRONMENT`\n   set to `development_pg` (your name might be different) i.e `ENVIRONMENT=DEVELOPMENT_PG rake db:migrate`. This will create the database tables\n   needed. Following this we need to migrate the individual table data. Which is 3 main tables; `mockdata`, `replacedata` \u0026 `rubyscripts`. We do this\n   by running the 3 migration scripts one by one from the `db/datamigration` directory. Ensure that the scripts have the correct old and new\n   environment names from the `database.yml` file. Once the data has been migrated successfully change the `Rakefile` or\n   the environment variable `ENVIRONMENT` to point to the correct db from the `database.yml` file.\n   \n### TODO's\n    * Video mocking\n    * Support more verbs when cloning (currently limited to GET) \n\n### Caveat\n    * The API URLs have to be unique across hosts as the mock server maintains only the mock url path and NOT the host part of the url.\n    * The tool and framework has been setup to work against a single client and does not guarantee behaviour when used\n      concurrently by more than one user. \n\n### Web interface   \n \n The tool/framework has an interface that lets you create and maintain mocking data.\n \n#### Home Screen\n![](https://github.com/mvemjsun/mock_server/blob/master/public/img/home_screen.png?raw=true)\n\n#### Advanced Options\n![](https://github.com/mvemjsun/mock_server/blob/master/public/img/advanced_options.png?raw=true)\n\n#### Replace Strings\n![](https://github.com/mvemjsun/mock_server/blob/master/public/img/replace_screen.png?raw=true)\n\n#### Search \n![](https://github.com/mvemjsun/mock_server/blob/master/public/img/search_screen.png?raw=true)\n\n#### Search Results\n![](https://github.com/mvemjsun/mock_server/blob/master/public/img/search_results.png?raw=true)\n\n## Copyright and License\n\nCopyright (c) 2016, mvemjsun.\n\nMocking bird source code is licensed under the [MIT License](LICENSE.md).\n","funding_links":[],"categories":["Testing"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvemjsun%2Fmock_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmvemjsun%2Fmock_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvemjsun%2Fmock_server/lists"}