{"id":20285417,"url":"https://github.com/mramshaw/simple-rest-api","last_synced_at":"2026-04-14T18:33:09.219Z","repository":{"id":57633878,"uuid":"97398263","full_name":"mramshaw/Simple-REST-API","owner":"mramshaw","description":"A proof of concept of a simple REST API in Golang. All data is held in memory, all transfer is via JSON. CORS is handled.","archived":false,"fork":false,"pushed_at":"2020-03-06T17:30:17.000Z","size":135,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-30T01:38:06.347Z","etag":null,"topics":["cors","go","golang","json","rest","rest-api","swagger"],"latest_commit_sha":null,"homepage":"","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/mramshaw.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}},"created_at":"2017-07-16T17:09:55.000Z","updated_at":"2021-10-11T13:43:25.000Z","dependencies_parsed_at":"2022-09-07T04:00:55.015Z","dependency_job_id":null,"html_url":"https://github.com/mramshaw/Simple-REST-API","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mramshaw/Simple-REST-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FSimple-REST-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FSimple-REST-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FSimple-REST-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FSimple-REST-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mramshaw","download_url":"https://codeload.github.com/mramshaw/Simple-REST-API/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FSimple-REST-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270691390,"owners_count":24629072,"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-08-16T02:00:11.002Z","response_time":91,"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":["cors","go","golang","json","rest","rest-api","swagger"],"created_at":"2024-11-14T14:26:32.296Z","updated_at":"2025-10-20T08:55:32.864Z","avatar_url":"https://github.com/mramshaw.png","language":"Go","readme":"# Simple REST API\n\n[![Build status](http://travis-ci.org/mramshaw/Simple-REST-API.svg?branch=master)](http://travis-ci.org/mramshaw/Simple-REST-API)\n[![Coverage Status](http://codecov.io/github/mramshaw/Simple-REST-API/coverage.svg?branch=master)](http://codecov.io/github/mramshaw/Simple-REST-API?branch=master)\n[![Go Report Card](http://goreportcard.com/badge/github.com/mramshaw/Simple-REST-API?style=flat-square)](http://goreportcard.com/report/github.com/mramshaw/Simple-REST-API)\n[![GoDoc](http://godoc.org/github.com/mramshaw/Simple-REST-API?status.svg)](http://godoc.org/github.com/mramshaw/Simple-REST-API)\n[![GitHub release](http://img.shields.io/github/v/release/mramshaw/Simple-REST-API?style=flat-square)](http://github.com/mramshaw/Simple-REST-API/releases)\n\nA proof of concept of a simple REST API in Golang.\n\nAll data is held in memory, all transfer is via JSON.\n\nAll testing can be with __curl__ or [Swagger](https://swagger.io/) - although Postman should work too.\n\n## Features\n\n- uses the excellent [Gorilla MUX](https://github.com/Gorilla/mux)\n- returns appropriate HTTP status codes\n- modify Person method implemented\n- uses __JSON__\n \nIn __Firefox__ at least, specifying \"application/json\" allows interpretation of the JSON:\n\n![JSON in Firefox](./json_in_firefox.png)\n\n## Installation\n\n- __Go__ is required (version 1.7 or later)\n\nFetch this project as follows:\n\n\t$ go get -u github.com/mramshaw/Simple-REST-API\n\nThis could also be done with __git__ of course:\n\n\t$ git clone https://github.com/mramshaw/Simple-REST-API.git\n\nAny dependencies will be fetched in the __build__ process.\n\n## Building\n\n- __make__ is required\n\nThis will fetch all dependencies, build, and run the executable:\n\n\t$ make\n\nLocal dependencies are stored in a local __api__ directory.\n\nAll other dependencies will be stored in a local __go__ directory.\n\n## Unit Tests\n\n- __make__ is required\n\nThis will run the unit tests for the DAO (api/people package):\n\n\t$ make test\n\nThe unit tests will be run in __verbose__ mode.\n\n## Usage\n\nBuild and run everything:\n\n\t$ make\n\nOr run the go code (Ctrl-C to terminate):\n\n\t$ PORT=8100 CORS_HOST=http://localhost:3200 go run RestfulGorillaMux.go\n\n[Specifying `CORS_HOST` allows the swagger-ui to function.]\n\nOr run the executable (Ctrl-C to terminate):\n\n\t$ PORT=8100 CORS_HOST=http://localhost:3200 ./RestfulGorillaMux\n\nThe API will then be accessible at:\n\n\thttp://localhost:8100/v1/people\n\n[Note that the API is __versioned__ (which is probably a best practice).]\n\n## Testing\n\nUse the following __curl__ commands to test (or use the Swagger UI as shown below).\n\nGET (All):\n\n\t$ curl -v localhost:8100/v1/people\n\nGET (Individual):\n\n\t$ curl -v localhost:8100/v1/people/5\n\n\t$ curl -v localhost:8100/v1/people/1\n\nPOST (Create):\n\n\t$ curl -v -X POST -H \"Content-Type: application/json\"   \\\n\t       -d '{\"firstname\":\"Tommy\",\"lastname\":\"Smothers\"}' \\\n\t       localhost:8100/v1/people/5\n\nPUT (Update):\n\n\t$ curl -v -X PUT -H \"Content-Type: application/json\" \\\n\t       -d '{\"firstname\":\"Tom\",\"lastname\":\"Smothers\",\"address\":{\"city\":\"Hollywood\",\"state\":\"CA\"}}' \\\n\t       localhost:8100/v1/people/5\n\nDELETE (Delete):\n\n\t$ curl -v -X DELETE -H \"Content-Type: application/json\" \\\n\t       localhost:8100/v1/people/5\n\n[Specifying __-v__ shows the HTTP status codes; this can be omitted if the status codes are not of interest.]\n\n## Swagger\n\nAlthough Postman is pretty nice, I've always found Swagger to be a better experience.\n\nThe content can be served from [swagger-ui](https://github.com/swagger-api/swagger-ui) (which uses __node__ and __npm__).\n\n![Swagger on chromium](./swagger.png)\n\nOn linux, CORS (Cross Origin Resource Sharing) may be temporarily disabled for __chromium__ as follows:\n\n    $ chromium-browser --disable-web-security --user-data-dir\n\n[This will only work if chromium is NOT running, as it will otherwise share the browser session.]\n\n## To Do\n\n- [x] Return appropriate HTTP status codes\n- [x] Implement code to modify a Person\n- [x] Modify to use __JSON__\n- [x] Implement API versioning\n- [x] Add a SWAGGER definition\n- [x] Implement CORS (Cross Origin Resource Sharing) handling\n- [x] Refactor data access into a DAO module\n- [x] Add tests for the DAO\n- [x] Add a health check\n- [x] Refactored code\n- [ ] Refactor code to NOT use Gorilla/mux\n- [x] Move configuration to environment variables (12-Factor everything)\n- [x] Make CORS hosts configurable\n- [ ] Implement graceful shutdown (available since __Go 1.8__)\n- [x] Implement continuous integration (Travis CI)\n- [x] Implement code coverage statistics (Codecov.io)\n- [x] Implement Go report card (Goreportcard.com)\n- [x] Implement [SemVer 2.0.0.](https://semver.org/spec/v2.0.0.html) release tagging\n- [x] Add link for Simple-REST-API GoDoc\n- [ ] Add Prometheus-style instrumentation\n- [ ] Implement method-based Basic AUTH\n- [ ] Implement a persistent back-end\n- [ ] Investigate upgrading to HTTP2\n- [x] Upgrade to latest release of Golang (1.14 as of the time of writing)\n- [x] Upgrade `release` badge to conform to new Shields.io standards\n\n## Credits\n\nInspired by, but since heavily mutated, this great tutorial by Nic Raboy:\n\n\thttps://www.thepolyglotdeveloper.com/2016/07/create-a-simple-restful-api-with-golang/\n\nThere is also a YouTube video (which is linked to from the article).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmramshaw%2Fsimple-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmramshaw%2Fsimple-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmramshaw%2Fsimple-rest-api/lists"}