{"id":13796860,"url":"https://github.com/rodkranz/fakeApi","last_synced_at":"2025-05-13T00:31:08.646Z","repository":{"id":82449001,"uuid":"76904040","full_name":"rodkranz/fakeApi","owner":"rodkranz","description":null,"archived":false,"fork":false,"pushed_at":"2018-01-23T15:50:18.000Z","size":383,"stargazers_count":75,"open_issues_count":0,"forks_count":2,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-03-16T02:47:32.415Z","etag":null,"topics":["api","bindata","fakeapi","golang"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rodkranz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-19T23:00:01.000Z","updated_at":"2023-07-08T16:17:05.000Z","dependencies_parsed_at":"2023-03-09T16:30:46.975Z","dependency_job_id":null,"html_url":"https://github.com/rodkranz/fakeApi","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/rodkranz%2FfakeApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodkranz%2FfakeApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodkranz%2FfakeApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodkranz%2FfakeApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodkranz","download_url":"https://codeload.github.com/rodkranz/fakeApi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225159881,"owners_count":17430204,"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","bindata","fakeapi","golang"],"created_at":"2024-08-03T23:01:16.850Z","updated_at":"2024-11-18T10:31:39.726Z","avatar_url":"https://github.com/rodkranz.png","language":"Go","funding_links":[],"categories":["Simulators"],"sub_categories":[],"readme":"# Fake API\n\nYou don't need to wait for backend delivery your api any more, you can simulate the api response with this simple fakeApi, \nyou can continue developing your frontend without dependencies.\n\nIt is a simple way to mock your api response.\n\n## Source ##\n\n* FakeApi Source\n* Version: 1.4.0\n* License: MIT-style\n\n## Summary ##\n\n* [Download](#download)\n* [Configure bindata](#configure-bindata)\n* [Requirements to build](#requirements-to-build)\n* [Execute](#execute)\n* [Seeds File](#seeds-file)\n* [Multiple Responses for Seed](#multiples-response-for-seed)\n* [Multiple Domains](#multiple-domains)\n* [Delay of response](#delay-of-response)\n* [Condition Status Code](#condition-status-code)\n* [List of links available (api)](#list-of-links-available)\n* [Web documentation](#web-documentation)\n* [Web documentation category](#docs-with-category)\n* [Seed file for documentation](#seed-file-for-documentation)\n* [Slack integration](#slack-integration)\n* [WebHook Autoupdate](#webhook-auto-update)\n* [FakeApi with Supervisor](#configuring-fakeapi-with-supervisor) - (writing...)\n* [FakeApi with Nginx](#configuring-fakeapi-with-nginx) - (writing...)\n\n## How to Compile it\n\n You can see the full available binary list [here](https://gobuild.io/rodkranz/fakeApi)\n or compile those files from different platforms in your owner computer.\n\n## Download\n\n You can just download and use, without compile anything.\n\n\n   Download for [Mac OSx](https://www.dropbox.com/s/6rnontns4510wbo/darwin_amd64.tar.gz?dl=0)\n\n   Download for [Linux x386](https://www.dropbox.com/s/ehf4kjqq9iex8oh/linux_386.tar.gz?dl=0)\n\n   Download for [Linux amd64](https://www.dropbox.com/s/j2yoxcsnlhykdow/linux_amd64.tar.gz?dl=0)\n\n   Download for [Windows x386](https://www.dropbox.com/s/4ygsrcqgaylurwu/windows_386.tar.gz?dl=0)\n\n   Download for [Windows x64](https://www.dropbox.com/s/y5xhtcdw7gvtd41/windows_amd64.tar.gz?dl=0)\n\n\n## Requirements to Build\n\n If you want to build in your own computer you need follow this steps below, if you don't want to build you can download at links above.\n\n* [GO Language](https://golang.org/doc/install)\n* [GO-Bindata](https://github.com/jteeuwen/go-bindata) - Component to help for settings\n    * To install `go get -u github.com/jteeuwen/go-bindata/...` \n\n#### Configure Bindata \n \nUse the script `init.sh` or the command \n```\n$ go-bindata -o \"./modules/bindata/bindata.go\" -pkg \"bindata\" conf/*\n```\n    \n\n#### Compiling to *Linux*\n\n\t$ env GOOS=linux GOARCH=arm GOARM=7 go build -o server main.go\n\n\n#### Compiling to *MacOSX*\n\n\t$ env GOOS=darwin GOARCH=386 go build -o server main.go\n\n\n#### Compiling to *Windows*\n\n\t$ env GOOS=windows GOARCH=386 go build -o server.exe main.go\n\n## Execute ##\n\nExecute `./server` or `./server web` to start server.\n\n\n## Seeds File ##\nIn a folder named `./fakes/default`, you need to have the **seed** (json files) that will represent your api, the server will read all files inside folder and load them.\nUse the file name to define the *URL* of api.\n\n**P.S.** All files seed needs to start with `api_[ANYTHING]`.\n\n**e.g.**: If file name is `api_account_signup.json` the url will be `/api/account/signup`.\n\n**The file seed needs to follow this format**: the seed file needs to follow this rules, *method*_*status_code*: *response* (Response can be any format)\n```\n{\n    \"[METHOD]_[STATUS_CODE]\": [RESPONSE]\n}\n```\n\n**Example seed format**: \n```\n{\n\t\"POST_200\": {\n        \"response\": \"Post Request with status code 200\",\n        \"statusCode: 200,\n\t}\n}        \n```\n\n**Example request**:\n```\ncurl -X POST \"http://localhost:9090/api/account/signup\"\n```\n\n**Response will be**: \n```\n{\n\t\"response\": \"POST Request with status code 200\",\n\t\"statusCode: 200,\n}\n```\n\n\n## Multiples Response for seed ##\n\nYou can add more then one response in seeds file for the same method and different methods too, just follow the rule in seed. \n\n**E.g**: Seed file name is `api_account_user.json` \n```\n{\n   \"GET_200\": {\n        \"response\": \"GET Request with status code 200\",\n        \"statusCode: 200,\n\t},\n    \"POST_400\": {\n        \"response\": \"POST Request with status code 400\",\n        \"statusCode: 400,\n        \"error\": {\n        \t\"email\": \"email has invalid format\",\n            \"time\": \"the date is invalid\"\n        }\n\t}\n    \"POST_200\": {\n        \"response\": \"Post Request with status code 200\",\n        \"statusCode: 200,\n\t}\n}\n```\n\n**Request POST**: \nwhen you are using multiple response and no specify the status code in your header request, the response will be random between data that you putting in your seed file.\n```\ncurl -X POST \"/api/account/user\"\n```\n\n**Response POST Dynamic**: \n```\n{\n\t\"response\": \"POST Request with status code 400\",\n\t\"statusCode: 400,\n\t\"error\": {\n\t\t\"email\": \"email has invalid format\",\n\t\t\"time\": \"the date is invalid\"\n\t}\n}\n```\nor \n```\n{\n\t\"response\": \"Post Request with status code 200\",\n\t\"statusCode: 200,\n}\n```\n\n**Request POST**: use the header `X-Fake-Response-Code` to specify the response that you want to receive.\n```\ncurl -X POST -H \"X-Fake-Response-Code: 400\" \"/api/account/user\"\n```\n\n**Response POST specific**: \n```\n{\n\t\"response\": \"POST Request with status code 400\",\n\t\"statusCode: 400,\n\t\"error\": {\n\t\t\"email\": \"email has invalid format\",\n\t\t\"time\": \"the date is invalid\"\n\t}\n}\n```\n\n**Multiples Response for some method**\n \n You can use multiple response for the same `method` and `status` for defined it you need to use as: \n\n**Request GET**: \n\n```\ncurl -X POST -H \"X-Fake-Response-Index: 1\" \"/api/account/user\"\n```\n\n**Response GET specific position**: \n\n```\n{\n   \"GET_200:0\": {\n        \"response\": \"First response of GET 200\",\n        \"statusCode: 200,\n   },\n   \"GET_200:1\": {\n        \"response\": \"Second response of GET 200\",\n        \"statusCode: 200,\n    },\n}\n``` \n \n If you specify slice by header as `X-Fake-Response-Index: 1` the fakeApi will return data at position\n   \n\n \n\n## Multiple Domains ##\n\nif you want to use multiples domain you just add a new folder inside of folder `fakes` and use the\nheader to specific the domain name. \n\nif you don't want to use the custom domain you can use `default` folder for yours files `seed`.\n\nFolders example: \n```\n➜  fakeApi git:(develop) ✗ ls -la fakes\ntotal 0\ndrwxr-xr-x   3 rlopes  staff   102B 22 Dec 23:34 default/\ndrwxr-xr-x   8 rlopes  staff   272B 23 Dec 00:11 hecate.com/\ndrwxr-xr-x   3 rlopes  staff   102B 22 Dec 23:33 olx.com/\n```\n\nRequest example: \n\n```\ncurl -X POST -H \"X-Fake-Domain: hecate.com\" \"http://localhost:9090/api/account/profile\"\n```\n\nResponse must be: \n```\n{\n  \"user\": {\n    \"company\": \"OLX\",\n    \"country\": \"PT\",\n    \"email\": \"rodrigo.lopes@olx.com\",\n    \"id\": 1,\n    \"name\": \"Rodrigo Lopes\",\n    \"phone\": \"000000000\",\n    \"phone_region\": \"PT\",\n    \"username\": \"rlopes\"\n  }\n}\n```\n\n## Delay of response ##\n\nIf you want to simulate delay of response you can use the header `X-Fake-Delay` to do that, use the `Millisecond`\n\n\nRequest example: \n\n```\ntime curl -X POST -H \"X-Fake-Delay: 3000\" -H \"X-Fake-Domain: hecate.com\" \"http://localhost:9090/api/account/profile\"\n```\n\nResponse example: \n\n```\ncurl ... 0.01s user 0.01s system 0% cpu 3.020 total\n```\n\n\n\n## Condition Status Code ##\nIf you want to set a condition for your DATA response,\nyou can test response `200` or `400` depending on value of request,\nyou can set a additional field named `CONDITIONS` for that,\nif body of request match with field `DATA` will render the method that indicated `ACTION`.\n\n```\n{\n    \"CONDITIONS\": [\n        {\n            \"ACTION\": \"POST_200\",\n            \"DATA\": {\n                \"username\": \"rodrigo.lopes@olx.com\",\n                \"password\": \"correct_password\"\n            }\n        },\n        {\n            \"ACTION\": \"POST_400\",\n            \"DATA\": {\n                \"username\": \"rodrigo.lopes@olx.com\",\n                \"password\": \"wrong_password\"\n            }\n        }\n    ],\n    \"INPUT\": {\n        \"username\": \"rodrigo.lopes@olx.com\",\n        \"password\": \"secret_password\"\n    },\n    \"POST_200\": {\n        \"message\": \"Account authentication with success\",\n        \"access_token\": \"2bc9ef94406489a5181fbd5898aa2202836810f2\",\n        \"success\": \"true\"\n    },\n    \"POST_400\": {\n        \"message\": \"Failed to authenticate user\",\n        \"success\": \"false\",\n        \"error\": {\n            \"exception\": \"Exception: invalid_grant\",\n            \"title\": \"Invalid username and password combination\"\n        }\n    }\n}\n```\n\n\n## List of links available ##\n\n You can see which links are available at FakeApi `seed` files, access the link `http://localhost:9090/api`\n this link will show list of endpoints available.\n\n\n#### Json documentation\n\nThe docs will be generate automatic \n```\n{\n    \"domain\": \"default\",\n    \"message\": \"List of endpoints available for this domain\",\n    \"resource\": {\n        \"Domain\": \"default\",\n        \"Path\": \"fakes/default\",\n        \"Docs\": [\n            {\n                \"Path\": \"fakes/default/api_account_confirmation_d019ccfd071164ae7ac8ca8a934a90e8b612.json\",\n                \"Url\": \"/api/account/confirmation/d019ccfd071164ae7ac8ca8a934a90e8b612\",\n                \"Error\": \"Something is worng with file api_account_confirmation_d019ccfd071164ae7ac8ca8a934a90e8b612.json error invalid character ':' after object key:value pair\",\n                \"Endpoints\": null\n            },\n            {\n                \"Path\": \"fakes/default/api_account_forgot_rodrigo.lopes@olx.com.json\",\n                \"Url\": \"/api/account/forgot/rodrigo.lopes@olx.com\",\n                \"Error\": null,\n                \"Endpoints\": [\n                    {\n                        \"Method\": \"GET\",\n                        \"StatusCode\": 200,\n                        \"StatusText\": \"OK\",\n                        \"Data\": {\n                            \"data\": {\n                                \"message\": \"User password recovery email was sent with success\",\n                                \"success\": true\n                            }\n                        }\n                    },\n                    ...\n                ]\n            },\n            ...\n        ]\n    }\n}\n```\n\n## Web documentation ##\n\nYou can use web page friendly if you access [http://localhost:9090/docs](http://localhost:9090/docs).\nthis page will be generate in realtime the documents that you have in `JSONS` file.\n\nThis is a simple example of page:\n\n![Docs Home Page](./docs/docs_01.png)\n\nWhen click at title the collapse will open then you can see the response.\n\n![Docs Collapse open](./docs/docs_02.png)\n\nIf the json has error the docs will render like this\n\n![Docs with error](./docs/docs_03.png)\n\n## Seed file for documentation ##\n\nIf you want to show more descriptions about your endpoint it is possible if you create a node `DOC` at you `Seed` files\nthis node needs to have set `title` and `description`, you can see the example above.\n\n * **DOC**:\n    * level: It is the category that this json belongs to. \n    * title: Title with little text about endpoint.\n    * description: Text more descriptive about what your endpoint does.\n * **INPUT** :\n\n    * The text saying what your endpoints are expecting to receive from client/frontend, it validate if format of request is equal what was written in seed.\n     \n\n\n*P.S*: Seed file with comments:\n\n```\n{\n    \"DOC\": {\n        \"title\": \"Validate account\",\n        \"description\": \"This endpoint will validate the account changing flag 'pending' to 'activate'.\"\n    },\n    \"INPUT\": {\n        \"email\": \"rodrigo.lopes@olx.com\",\n        \"token\": \"d019ccfd071164ae7ac8ca8a934a90e8b612\"\n    },\n    \"POST_201\": {\n        \"data\": {\n            \"success\": true,\n            \"message\": \"OK\"\n        }\n    }\n}\n```\n\nThe web page will be rendered this `seed` above like it:\n\n![Docs with texts](./docs/docs_04.png)\n\n\n## Configuring *FakeApi* with *Supervisor*.\n\nYou need to enter in folder `/etc/supervisor/conf.d` and create a file with name `fake-api.conf`\nand inside you have so set the environment.\n\n * My app is in `/var/www/fakeApi`\n * My logs are in `/var/log/fakeApi`\n\n```\n[program:FakeApi]\nenvironment=MACARON_ENV=production,FAKE_API=/var/www/fakeapiFAKE_API_CUSTOM=/var/www/fakeapi\ndirectory=/var/www/fakeapi\ncommand=/var/www/fakeapi/server web\nautostart=true\nautorestart=true\nstderr_logfile=/var/log/fakeApi/err.log\nstdout_logfile=/var/log/fakeApi/out.log\n```\n\n## Configuring *FakeApi* with *Nginx*.\n\n\u003e I am writing this step ....\n\n```\nserver {\n    listen   80; ## listen for ipv4; this line is default and implied\n    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6\n\n    root /usr/share/nginx/www;\n    index index.html index.htm;\n\n    # Make site accessible from http://localhost/\n    server_name localhost fake-api.local fake-api.olx.com;\n\n    location / {\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $remote_addr;\n        proxy_set_header X-Fake-Domain $host;\n        proxy_set_header Host $host;\n        proxy_pass http://127.0.0.1:9090;\n    }\n\n    # Next config of nginx...\n}\n```\n\n---\n*P.S*: By default the cross domain is always enabled.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodkranz%2FfakeApi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodkranz%2FfakeApi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodkranz%2FfakeApi/lists"}