{"id":20459771,"url":"https://github.com/rosbit/http-mock","last_synced_at":"2025-10-13T13:40:24.771Z","repository":{"id":144249440,"uuid":"190336595","full_name":"rosbit/http-mock","owner":"rosbit","description":"HTTP server mock with easy configuration","archived":false,"fork":false,"pushed_at":"2019-06-06T06:36:16.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-13T16:40:11.221Z","etag":null,"topics":["configuration","go","golang","http","mock","yaml"],"latest_commit_sha":null,"homepage":"","language":"Go","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/rosbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-06-05T06:15:22.000Z","updated_at":"2019-06-11T06:16:54.000Z","dependencies_parsed_at":"2023-05-29T06:00:23.594Z","dependency_job_id":null,"html_url":"https://github.com/rosbit/http-mock","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rosbit/http-mock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fhttp-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fhttp-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fhttp-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fhttp-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosbit","download_url":"https://codeload.github.com/rosbit/http-mock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fhttp-mock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015353,"owners_count":26085684,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["configuration","go","golang","http","mock","yaml"],"created_at":"2024-11-15T12:17:13.703Z","updated_at":"2025-10-13T13:40:24.706Z","avatar_url":"https://github.com/rosbit.png","language":"Go","readme":"# http-mock\n\n1. `http-mock` is intended to provide a mock HTTP server,  the repsonses of which are read from a YAML config file.\n1. `http-mock` supports 4 types of body\n    - body\n       - The value of `body` as response body content will be output to HTTP client without any change.\n    - file-body\n       - The value of `file-body` is a file name, the content of which will be output to the client.\n    - tmpl-body\n       - The value of `tmpl-body` is looked as the content of a template, so template actions will be evaluated before outputing the result.\n    - redirect-body\n       - the value of `redirect-body` is a URL string, which will be redirected to with a 302 response status.\n\n## Configuration\n\n- http-mock makes use of YAML as its configuratoin.\n\n- There's a sample configuration file [config.sample.yaml](config.sample.yaml)\n\n ```yaml\n  port: 8080\n  \n  # remove static-home if no static files to show\n  static-home:\n    root: ./static\n    alias: /static\n  \n  # remove any CORS header if needed\n  cors:\n    allow-origin: \"*\"\n    allow-headers: \"Content-Type, Authorization, Accept, X-Requested-With\"\n    allow-methods: \"GET, PUT, POST, DELETE, OPTIONS\"\n    expose-headers: \"X-Total-Count, X-Limit-Count, Link\"\n    allow-credentials: \"*\"\n  \n  default-content-type: \"application/json\"\n  \n  actions:\n    -\n      uri: /\n      method: \"GET, POST\"\n      response:\n        status: 200\n        headers:\n          content-type: \"text/plain\"\n        cookies:\n          cookie-name: cookie-value\n        tmpl-body: |-\n          Welcome to use\n          http-mock\n          {{ .r.Method }}\n    -\n      uri: /ping\n      method: \"GET, POST\"\n      response:\n        body: |-\n          {\n             \"code\": 200,\n             \"msg\": \"OK\"\n          }\n    -\n      uri: /api/users/:id\n      response:\n        tmpl-body: '{\"code\":200,\"msg\":\"OK\", \"id\": \"{{pathVar .r \"id\"}}\"}'\n    -\n      uri: /showfile\n      response:\n        content-type: \"text/plain\"\n        file-body: a-file.txt\n    -\n      uri: /redirect\n      response:\n        redirect-body: /\n  \n ```\n\n## Usage\n 1. with go1.11.x or above\n\n 2. change to any directory, run the commands\n\n    ```bash\n    $ git clone https://github.com/rosbit/http-mock\n    $ cd http-mock\n    $ go build\n    ```\n\n 3. if everything is ok, there will be an executable `http-mock` under the directory\n\n 4. for binary output under Linux/macos, click [releases](https://github.com/rosbit/http-mock/releases) to download it.\n\n 5. run `http-mock` with an env variable `CONF_FILE` pointed to the configuration file\n\n     ```bash\n     $ CONF_FILE=./config.sample.yaml ./http-mock\n     I am listening at :8080...\n     ```\n\n 6. open another terminal window, run `curl` to see the result\n\n     ```bash\n     $ curl http://localhost:8080/\n     Welcome to use\n     http-mock\n     GET\n     \n     $ curl http://localhost:8080/showfile\n     this is the content of a-file\n     \n     $ curl http://localhost:8080/api/users/1\n     {\"code\":200,\"msg\":\"OK\", \"id\": \"1\"}\n     \n     $ curl -X POST http://localhost:8080/ping\n     {\n        \"code\": 200,\n        \"msg\": \"OK\"\n     }\n     \n     $ curl http://localhost:8080/static/a-file.txt  # static file\n     this is the content of a-file\n     \n     $ curl -D - http://localhost:8080/redirect\n     HTTP/1.1 301 Moved Permanently\n     Access-Control-Allow-Credentials: *\n     Access-Control-Allow-Headers: Content-Type, Authorization, Accept, X-Requested-With\n     Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS\n     Access-Control-Allow-Origin: *\n     Access-Control-Expose-Headers: X-Total-Count, X-Limit-Count, Link\n     Content-Type: text/html; charset=utf-8\n     Location: /\n     Date: Wed, 05 Jun 2019 06:43:58 GMT\n     Content-Length: 36\n     \n     \u003ca href=\"/\"\u003eMoved Permanently\u003c/a\u003e.\n     \n     ```\n\n## Contribution\n\nPull requests are welcome! Also, if you want to discuss something send a pull request with proposal and changes.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fhttp-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosbit%2Fhttp-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fhttp-mock/lists"}