{"id":13991604,"url":"https://github.com/six-ddc/mirage","last_synced_at":"2025-04-14T12:12:34.786Z","repository":{"id":36197968,"uuid":"164539286","full_name":"six-ddc/mirage","owner":"six-ddc","description":"A web DSL and command-line tool for easily writing simple HTTP server","archived":false,"fork":false,"pushed_at":"2023-08-24T20:27:06.000Z","size":27,"stargazers_count":44,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T12:12:29.327Z","etag":null,"topics":["command-line","dsl","groovy","http-server","static-file-server"],"latest_commit_sha":null,"homepage":"","language":"Java","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/six-ddc.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}},"created_at":"2019-01-08T02:25:38.000Z","updated_at":"2024-03-31T14:21:57.000Z","dependencies_parsed_at":"2024-03-08T04:46:09.161Z","dependency_job_id":null,"html_url":"https://github.com/six-ddc/mirage","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/six-ddc%2Fmirage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/six-ddc%2Fmirage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/six-ddc%2Fmirage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/six-ddc%2Fmirage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/six-ddc","download_url":"https://codeload.github.com/six-ddc/mirage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877959,"owners_count":21176244,"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":["command-line","dsl","groovy","http-server","static-file-server"],"created_at":"2024-08-09T14:01:28.987Z","updated_at":"2025-04-14T12:12:34.766Z","avatar_url":"https://github.com/six-ddc.png","language":"Java","funding_links":[],"categories":["Java","Web服务器"],"sub_categories":["微服务框架"],"readme":"# mirage\n\n![](https://github.com/six-ddc/mirage/workflows/mvn/badge.svg)\n\nA web DSL to easily create a simple HTTP server\n\n## Features\n\n- **DSL syntax:** Human-readable [DSL](http://docs.groovy-lang.org/docs/latest/html/documentation/core-domain-specific-languages.html) syntax, let us be more intuitive write we need to provide HTTP server.\n\n- **Data Faker:** Add [Java Faker](https://github.com/DiUS/java-faker) for generating mock data such as names, addresses, and phone numbers.\n\n- **Out of the box:** After a simple installation, you run it on CLI without any configuration or modification.\n\n- **File watching:** Server will automatically reload when the specified files has been changed.\n\n- **High performance:** The Web framework implementation is based on [Spring Boot](https://spring.io/projects/spring-boot), and DSL syntax is based on [Groovy](http://groovy-lang.org/).\n\n## Requirements\n\n- Java (1.7 or newer)\n- Maven (if build)\n\n## Download / Installation\n\n```shell\nmake \u0026\u0026 make install\n```\n\nRelease binaries are available from [GitHub releases](https://github.com/six-ddc/mirage/releases).\n\n## Usage\n\n```\nusage: mirage [-p \u003cport\u003e] [-c \u003cscript\u003e] [file|dir]...\nA web DSL to easily create a simple HTTP server\n\n -c,--script \u003cscript\u003e       raw dsl script\n    --ext \u003cext\u003e             specify DSL file extension when the command\n                            arguments contains directory, (default: mir)\n -h,--help                  print help message\n -n,--interval \u003cinterval\u003e   specify update interval in seconds\n -p,--port \u003cport\u003e           specify server port (default 8080)\n\nFor more information, see https://github.com/six-ddc/mirage\n```\n\n### Examples\n\n#### hello world\n\n```shell\nmirage -c 'get(\"/hello\") { resp.println \"world!\"}'\n# curl http://127.0.0.1:8080/hello\n# world!\n```\n\n#### static file server\n\n```shell\nmirage -c 'get(\"/files/**\") { resp.index \".\" }'\n# curl http://127.0.0.1:8080/files/pom.xml\n```\n\n#### mock user data\n\n* create file `user.mir` and typing\n\n```groovy\nhandle path: '/user/{uid}/get', method: \"GET\", {\n\n    sleep 100.millisecond\n\n    resp.json {\n        id req.pathVariables.uid\n        name random.forRegex(/[A-Z][a-z]{3,10}/)\n        t new Date()\n        data {\n            contact 1..2, {\n                id it\n                name faker.name().name()\n                address faker.address().fullAddress()\n                phone faker.phoneNumber().cellPhone()\n            }\n        }\n    }\n}\n\nget('/user/{uid}/get2') {\n\n    // and also you can write json response directly\n    resp.eval \"\"\"{\n        \"id\": \"${req.pathVariables.uid}\",\n        \"name\": \"${random.forRegex(/[A-Z][a-z]{3,10}/)}\",\n        \"t\": \"${new Date()}\",\n        \"data\": {\n            \"contact\": [\n                {\n                    \"id\": 1,\n                    \"name\": \"${faker.name().name()}\",\n                    \"address\": \"${faker.address().fullAddress()}\",\n                    \"phone\": \"${faker.phoneNumber().cellPhone()}\"\n                },\n                {\n                    \"id\": 2,\n                    \"name\": \"${faker.name().name()}\",\n                    \"address\": \"${faker.address().fullAddress()}\",\n                    \"phone\": \"${faker.phoneNumber().cellPhone()}\"\n                }\n            ]\n        }\n    }\"\"\"\n}\n```\n\n* run\n\n```shell\nmirage user.mir\n```\n\n* test server\n\n```json\n$ curl -s http://127.0.0.1:8080/user/1234/get | jq .\n$ curl -s http://127.0.0.1:8080/user/1234/get2 | jq .\n{\n  \"id\": \"1234\",\n  \"name\": \"Astn\",\n  \"t\": \"2019-11-17T04:04:55+0000\",\n  \"data\": {\n    \"contact\": [\n      {\n        \"id\": 1,\n        \"name\": \"Bryan Bashirian\",\n        \"address\": \"22474 Bashirian Ways, New Thanhfurt, MA 32424-5437\",\n        \"phone\": \"(973) 158-7100\"\n      },\n      {\n        \"id\": 2,\n        \"name\": \"Charley Jast\",\n        \"address\": \"526 Corkery Rue, Lake Moises, MO 28747\",\n        \"phone\": \"1-418-198-2865\"\n      }\n    ]\n  }\n}\n```\n\n## Performance\n\nMy test machine is an Intel Core i5 2.7 GHz, 2 CPUs, 8 GB Memory\n\n```shell\n$ mirage -c 'get(\"/hello\") { resp.println \"world!\"}'\n```\n\n```shell\n$ wrk -c 10 -t 10 -d 1s --latency http://127.0.0.1:8080/hello\nRunning 1s test @ http://127.0.0.1:8080/hello\n  10 threads and 10 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency   847.57us    1.45ms  27.75ms   93.86%\n    Req/Sec     1.74k   528.60     3.22k    77.27%\n  Latency Distribution\n     50%  457.00us\n     75%  815.00us\n     90%    1.63ms\n     99%    7.03ms\n  19082 requests in 1.10s, 2.31MB read\nRequests/sec:  17335.71\nTransfer/sec:      2.10MB\n```\n\n## License\n\n[MIT](https://tldrlegal.com/license/mit-license)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsix-ddc%2Fmirage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsix-ddc%2Fmirage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsix-ddc%2Fmirage/lists"}