{"id":38088959,"url":"https://github.com/nmezhenskyi/go-rest-api-example","last_synced_at":"2026-01-16T20:56:04.943Z","repository":{"id":126089002,"uuid":"474452849","full_name":"nmezhenskyi/go-rest-api-example","owner":"nmezhenskyi","description":"A minimalistic REST API written in Go using only the standard library.","archived":false,"fork":false,"pushed_at":"2022-05-15T18:06:35.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T20:06:03.232Z","etag":null,"topics":["go","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","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/nmezhenskyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2022-03-26T19:56:48.000Z","updated_at":"2022-08-21T15:05:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"3f5b3b5b-f958-4975-b44a-202f08491432","html_url":"https://github.com/nmezhenskyi/go-rest-api-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nmezhenskyi/go-rest-api-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmezhenskyi%2Fgo-rest-api-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmezhenskyi%2Fgo-rest-api-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmezhenskyi%2Fgo-rest-api-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmezhenskyi%2Fgo-rest-api-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nmezhenskyi","download_url":"https://codeload.github.com/nmezhenskyi/go-rest-api-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmezhenskyi%2Fgo-rest-api-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28482424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["go","rest-api"],"created_at":"2026-01-16T20:56:04.862Z","updated_at":"2026-01-16T20:56:04.926Z","avatar_url":"https://github.com/nmezhenskyi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go REST API Example\n\nThis project showcases a minimalistic REST API written in Go using only the standard library. It serves as an overview of core Go concepts.\n\nThe program relies on a custom router, in-memory storage, and `net/http` package. The purpose of this API is to manage the resource *Wine*.\n\n## Disclaimer\n\nThis example is not a production ready code. Many techniques used in the project have an introductory purpose. They aim to demonstrate fundamental concepts in a readable and easy-to-understand manner.\nNamely, the custom router used by the application is inefficient compared to more complex solutions such as [httprouter](https://github.com/julienschmidt/httprouter). Likewise, in-memory hash table is not a persistent way to store data. However, this project serves as a good example on how to structure a Go application, manage dependencies, and unit tests.\n\n## Functionality\n\nThe API supports 6 HTTP end-points:\n\n- `GET \"/\"`\n- `GET \"/api/wine\"`\n- `GET \"/api/wine/:id\"`\n- `POST \"/api/wine\"`\n- `PUT \"/api/wine/:id\"`\n- `DELETE \"/api/wine/:id\"`\n\nThe underlying resource is *Wine* with the following schema:\n\n```json\n{\n   \"id\": {\n      \"type\": \"string\",\n      \"example\": \"1\",\n   },\n   \"name\": {\n      \"type\": \"string\",\n      \"example\": \"Example Wine\"\n   },\n   \"category\": {\n      \"type\": \"string\",\n      \"example\": \"Some category\"\n   },\n   \"label\": {\n      \"type\": \"string\",\n      \"example\": \"Some label description\"\n   },\n   \"volume\": {\n      \"type\": \"string\",\n      \"example\": \"0.7\"\n   },\n   \"region\": {\n      \"type\": \"string\",\n      \"example\": \"Some region\"\n   },\n   \"producer\": {\n      \"type\": \"string\",\n      \"example\": \"Some producer\"\n   },\n   \"year\": {\n      \"type\": \"number\",\n      \"example\": 2022\n   },\n   \"alcohol\": {\n      \"type\": \"string\",\n      \"example\": \"11.5%\"\n   },\n   \"price\": {\n      \"type\": \"string\",\n      \"example\": \"12.50\"\n   }\n}\n```\n\n## Project Structure\n\n- `/cmd`\n  - `/restapi/main.go`: entry point that begins the execution of the program\n- `/internal`\n  - `/router`: custom http router\n  - `/storage`: wrapper for a hash table to use as in-memory storage\n  - `/webserver`: http webserver implementation and route handlers\n  - `/model`: contains domain model *Wine*\n- `/data`\n  - `/data_sample.json`: sample data for the webserver\n\n## Commands\n\nCompile:\n\n- `go build -o ./bin/restapi ./cmd/restapi`\n\nStart the server:\n\n- `./bin/restapi` or `go run ./cmd/restapi`\n\nRun tests:\n\n- `go test ./internal/webserver`\n\nAlternatively you can use Makefile\n\n## Further Recommendations\n\n- [Mat Ryer talks about best practices for writing HTTP Web Services in Go.](https://www.youtube.com/watch?v=rWBSMsLG8po\u0026list=PLhp8mtvB6UEDCuvKT6ESWgJ0udJtWa09g\u0026index=1\u0026t=822s)\n- [Detailed example of how to set up a file structure for a Go application.](https://github.com/golang-standards/project-layout)\n- [Gregory Schier explains how to build a simple router in Go.](https://codesalad.dev/blog/how-to-build-a-go-router-from-scratch-3)\n- [Fast and efficient router based on a Radix Tree.](https://github.com/julienschmidt/httprouter)\n\n## Contribute\n\nFeel free to send a pull request with new features or bugfix, and to open a new issue with recommendations or suggestions.\n\n## License\n\nThis source code is licensed under MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmezhenskyi%2Fgo-rest-api-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnmezhenskyi%2Fgo-rest-api-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmezhenskyi%2Fgo-rest-api-example/lists"}