{"id":30945544,"url":"https://github.com/napcs/demo-api","last_synced_at":"2025-09-10T23:54:14.280Z","repository":{"id":64307009,"uuid":"146843877","full_name":"napcs/demo-api","owner":"napcs","description":"A lightweight local http server with CORS support that serves JSON data via a REST API. Great for testing stuff.","archived":false,"fork":false,"pushed_at":"2018-09-03T16:27:28.000Z","size":13,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T12:45:43.236Z","etag":null,"topics":["api-server","cli"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/napcs.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}},"created_at":"2018-08-31T05:05:20.000Z","updated_at":"2019-11-18T10:29:20.000Z","dependencies_parsed_at":"2022-12-06T09:48:50.323Z","dependency_job_id":null,"html_url":"https://github.com/napcs/demo-api","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/napcs/demo-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/napcs%2Fdemo-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/napcs%2Fdemo-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/napcs%2Fdemo-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/napcs%2Fdemo-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/napcs","download_url":"https://codeload.github.com/napcs/demo-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/napcs%2Fdemo-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274550592,"owners_count":25306364,"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-09-10T02:00:12.551Z","response_time":83,"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":["api-server","cli"],"created_at":"2025-09-10T23:54:10.472Z","updated_at":"2025-09-10T23:54:14.269Z","avatar_url":"https://github.com/napcs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# demo-api\n\nA simple command-line JSON server that also emulates a REST API. If you need to stub out an API locally, this is the tool you need. It's lightweight, works on Mac, Windows, and Linux, and requires no setup other than a JSON data file. \n\n## Usage\n\nCreate a JSON file called `data.json`:\n\n```json\n{\n  \"notes\" : [\n    {\n      \"id\" : 1,\n      \"title\" : \"Hello World\"\n    },\n    {\n      \"id\" : 2,\n      \"title\" : \"The second note\"\n    }\n  ]\n}\n```\n\nThen run `demo-api`.  The server starts up. \n\nVisit `http://localhost:8080` in the browser to serve the entire file as a JSON response.\n\nIn addition, since the JSON file is structured like a typical REST API data structure, the following endpoints will work:\n\n* `GET http://localhost:8080/notes` - retrive all \"notes\"\n* `GET http://localhost:8080/notes/1` - retrive the note with the `id`   of `1`\n* `POST http://localhost:8080/notes/` with JSON payload - Create a new note. This modifies the `data.json` file.\n* `PUT/PATCH http://localhost:8080/notes/1` with JSON payload - update the note with the `id`   of `1`. This modifies the `data.json` file.\n* `DELETE http://localhost:8080/notes/1` - Delete the note with the `id`   of `1`. This modifies the `data.json` file.\n\n\nAnything that doesn't match returns a `404` status code.\n\n## Examples with `curl`\n\nGiven the following data file:\n\n\n```json\n{\n  \"notes\" : [\n    {\n      \"id\" : 1,\n      \"title\" : \"Hello World\"\n    },\n    {\n      \"id\" : 2,\n      \"title\" : \"The second note\"\n    }\n  ]\n}\n```\n\nTo get everything:\n\n```\ncurl -i localhost:8080/\n```\n\nTo get the `notes` node:\n\n\n```\ncurl -i localhost:8080/notes\n```\n\nTo get the `notes/1` node:\n\n\n```\ncurl -i localhost:8080/notes/1\n```\n\nTo add a new note:\n\n```\ncurl -i -X POST http://localhost:8080/notes \\\n-H \"Content-type: application/json\" \\\n-d '{\"title\": \"This is another note\"}'\n```\n\nTo update the contents of the first note:\n\n```\ncurl -i -X PUT http://localhost:3000/notes/1  \\\n-H \"Content-type: application/json\" \\\n-d '{\"title\": \"This is the third note\"}'\n```\n\nTo delete the third note:\n\n```\ncurl -i -X DELETE localhost:3000/notes/3\n```\n\nIf you use a different JSON file, your paths will be different.\n\n### Advanced Usage\n\nTo specify a different port, use the `-p` option:\n\n```\ndemo-api -p 4000\n```\n\nTo specify a different filename, in case you don't like `data.json` as the default, use `-f` and specify the file:\n\n\n```\ndemo-api -f notes.json\n```\n\nTo view the version, use `-v`:\n\n```\ndemo-api -v\n```\n\n## Installation\n\nTo install, download the latest release to your system and copy the executable to a location on your path. Then launch it in a directory containing `data.json`.\n\n\n## Roadmap\n\n* Refactoring. This code is a mess.\n* A \"no persist\" mode - changes are accepted but not saved to the JSON file.\n\n## Contributing\n\nPlease contribute.\n\nClone the repository and then download the dependencies:\n\n```\n$ go get github.com/Jeffail/gabs\n$ go get github.com/gin-gonic/gin\n$ go get github.com/codegangsta/gin\n```\n\nRun development version:\n\n```\n$ gin --appPort 8080 go run app.go\n```\n\nThe server is now listening on `localhost:3000` and will reload on code change.\n\nMake changes, run the tests, create a PR. \n\n## History\n\n* 2018-09-03 - v0.3.0\n  * Refactoring to make testing possible\n  * Adds test suite\n  * Pretty print\n  * Supports `PUT` and `PATCH`\n  * Supports `-v` option to show version\n  * Supports `-f` option to specify the data file\n  * Supports `-p` option to specify the port\n  * Fix bug where querying non-existant ID still returned a 200 status code instead of 404\n* 2018-08-30 - v0.1.0\n  * initial release\n\n## License\n\nApache 2. See LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnapcs%2Fdemo-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnapcs%2Fdemo-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnapcs%2Fdemo-api/lists"}