{"id":15538599,"url":"https://github.com/cyrilbois/mockae","last_synced_at":"2025-08-08T17:34:44.336Z","repository":{"id":251817613,"uuid":"838514732","full_name":"cyrilbois/mockae","owner":"cyrilbois","description":"The most flexible way to mock REST APIs with Lua code execution","archived":false,"fork":false,"pushed_at":"2024-09-06T19:28:24.000Z","size":34,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-09T12:33:06.899Z","etag":null,"topics":["api","lua","mock"],"latest_commit_sha":null,"homepage":"https://mockae.com/","language":"JavaScript","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/cyrilbois.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":"2024-08-05T19:51:57.000Z","updated_at":"2024-09-23T17:19:43.000Z","dependencies_parsed_at":"2025-03-06T13:31:39.422Z","dependency_job_id":null,"html_url":"https://github.com/cyrilbois/mockae","commit_stats":null,"previous_names":["cyrilbois/mockae"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrilbois%2Fmockae","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrilbois%2Fmockae/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrilbois%2Fmockae/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrilbois%2Fmockae/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cyrilbois","download_url":"https://codeload.github.com/cyrilbois/mockae/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250458677,"owners_count":21433915,"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":["api","lua","mock"],"created_at":"2024-10-02T12:05:03.458Z","updated_at":"2025-04-23T15:25:15.644Z","avatar_url":"https://github.com/cyrilbois.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mockae\n\nMockae is a versatile tool that allows you to mock REST APIs using Lua code execution. It allows to easily simulate and test API behaviors, providing a dynamic environment to craft custom responses and logic.\n\n## Install\n\n```shell\n$ npm install mockae\n\n# Or clone the repository\n$ git clone https://github.com/cyrilbois/mockae.git\n$ cd mockae\n$ npm install\n```\n\n## Configuration\n\nCreate a `db.json` file\n\n```json\n{\n  {\n    \"products\": [\n      {\n        \"id\": 1, \"name\": \"T-shirt\", \"price\": 19.99\n      },\n      {\n        \"id\": 2, \"name\": \"Jeans\", \"price\": 49.99\n      }\n    ],\n    \"users\": [\n      {\n        \"id\": 1, \"username\": \"johndoe\", \"email\": \"johndoe@example.com\"\n      },\n      {\n        \"id\": 2, \"username\": \"janedoe\", \"email\": \"janedoe@example.com\"\n      }\n    ]\n}\n}\n```\nIn this example, you have created 2 resources: \"products\" and \"users\" (2 objects for each resource).\n\nCreate a `rules.lua` file\n\n```lua\nif request.method() == \"POST\" and request.pathname() == \"/users\" then\n    response.status(400)\n    response.send('{' .. \n                  '\"error\":\"Bad Request\",\\n' ..\n                  '\"message\":\"Missing required field: email\"' ..\n                '}')\n    return response.exit()\nend\n```\nWith these rules, when calling the creation of a \"users\" a 400 error is returned.\n\n## Usage\n\nStart the REST API service\n\n```shell\n$ npx mockae\n\n# Or if you have cloned the repository\n$ npm start\n```\n\nGet a REST API\n\n```shell\n$ curl http://localhost:3000/products/1\n{\n    \"id\": 1,\n    \"name\": \"T-shirt\",\n    \"price\": 19.99\n}\n```\n\n## Routes\n\nThe REST API handles different HTTP methods for creating, retrieving, updating, and deleting resources\n\n\n```\nGET     /products     Returns all products\nGET     /products/2   Returns the product with ID 2\nPOST    /products     Create a new product\nGET     /products/2   Returns the product with ID 2\nPUT     /products/2   Update the product with ID 2\nPATCH   /products/2   Update partially the product with ID 2\nDELETE  /products/2   Delete the product with ID 2\n```\n\nA public API is available on [mockae.com](https://mockae.com) to test this fake API.\n\n### Pagination\n\n- page\n- limit \n\n```\nGET     /products?limit=5         Returns the first 5 products (Page defaults to 1)\nGET     /products?page=2          Returns 10 products from the second page (default limit is 10)\nGET     /products?page=2\u0026limit=5  Returns 5 products from the second page (Page starts at 1)\n```\n\n## Custom rules\n\nCustom rules are Lua code that allow you to modify the behavior of the fake REST API. With custom rules, you can set conditions based on the request (such as HTTP method, headers, and payload) and define the response (including HTTP status code and payload). This enables you to tailor the API's behavior to suit specific testing and development scenarios.\n\nThe Request and Response objects are provided to define the rules.\n\n### Request\n\nThe Request object is used to represent the request data.\n\n```md\n| Method                  | Description                                                                        |\n|-------------------------|------------------------------------------------------------------------------------|\n| request.header(name)    | Returns the header `name`                                                          |\n| request.method()        | Returns the HTTP method ('GET', 'POST', 'PUT', 'PATCH', 'DELETE')                  |\n| request.url()           | Returns the pathname of the URL (e.g., /users/23).                                 |\n| request.id()            | Returns the resource ID                                                            |\n| request.resource()      | Returns the resource                                                               |\n| request.payload(name)   | Returns the attribute of the payload object with the name specified in `name`      |\n```\n\n###  Response\n\nThe Response object is used to update the response, including the HTTP status, headers, and payload.\n\n```md\n| Method                     | Description                                                                                     |\n|----------------------------|-------------------------------------------------------------------------------------------------|\n| response.status(status)    | Sets the HTTP status (e.g., 200, 404, etc.)                                                     |\n| response.send(payload)     | Sets the response payload                                                                       |\n| response.header(name, value) | Sets the header name to value                                                                  |\n| response.exit()            | Stops the standard execution of the API (No action or resource loading will be performed)       |\n```\n\n## Contributing\nContributions are welcome! If you have ideas, improvements, or bug fixes, feel free to submit a pull request. \nPlease ensure your changes keep things simple and easy to maintain. Thank you for helping make this project better!\n\n## Tests\n\nLaunch tests\n\n```shell\n$ npm test\n```\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyrilbois%2Fmockae","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyrilbois%2Fmockae","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyrilbois%2Fmockae/lists"}