{"id":14987701,"url":"https://github.com/hwangseonu/gin-restful","last_synced_at":"2025-10-05T20:53:09.600Z","repository":{"id":57490493,"uuid":"174893876","full_name":"hwangseonu/gin-restful","owner":"hwangseonu","description":"A Go library that simplifies and accelerates RESTful API development using the Gin framework. It abstracts away repetitive routing and handler setups, allowing you to easily implement Create, Read, Update, Delete (CRUD) functionalities.","archived":false,"fork":false,"pushed_at":"2025-09-27T02:02:41.000Z","size":55,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-27T03:31:56.364Z","etag":null,"topics":["backend","extension","gin","gin-gonic","go","golang","library","rest","rest-api","restful","restfull-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/hwangseonu.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-03-10T23:30:40.000Z","updated_at":"2025-09-27T02:02:44.000Z","dependencies_parsed_at":"2025-09-27T03:24:44.268Z","dependency_job_id":"877cf22a-95f9-4256-9e2f-b9c2858b28b7","html_url":"https://github.com/hwangseonu/gin-restful","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hwangseonu/gin-restful","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwangseonu%2Fgin-restful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwangseonu%2Fgin-restful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwangseonu%2Fgin-restful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwangseonu%2Fgin-restful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hwangseonu","download_url":"https://codeload.github.com/hwangseonu/gin-restful/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwangseonu%2Fgin-restful/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278518904,"owners_count":26000177,"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-10-05T02:00:06.059Z","response_time":54,"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":["backend","extension","gin","gin-gonic","go","golang","library","rest","rest-api","restful","restfull-api"],"created_at":"2024-09-24T14:15:14.054Z","updated_at":"2025-10-05T20:53:09.593Z","avatar_url":"https://github.com/hwangseonu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-restful\n[![Go Reference](https://pkg.go.dev/badge/github.com/hwangseonu/gin-restful.svg)](https://pkg.go.dev/github.com/hwangseonu/gin-restful)\n[![CodeFactor](https://www.codefactor.io/repository/github/hwangseonu/gin-restful/badge)](https://www.codefactor.io/repository/github/hwangseonu/gin-restful)\n\nA Go library that simplifies and accelerates RESTful API development using the Gin framework. It abstracts away repetitive routing and handler setups, allowing you to easily implement **Create, Read, Update, Delete (CRUD)** functionalities.\n\n## Key Features\n\n* **Automatic Routing:** Automatically maps HTTP methods (POST, GET, PUT, DELETE) to the corresponding CRUD functions defined in the `restful.Resource` interface.\n* **Interface-Based Development:** Provides a consistent way to define API resources by simply implementing a predefined interface.\n* **Easy Schema Binding:** The `RequestBody` method allows you to easily define the JSON schema for incoming request bodies.\n\n## Getting Started\n\n### Installation\n\nFirst, install the Gin framework and the `gin-restful` library.\n\n```bash\ngo get github.com/gin-gonic/gin\ngo get github.com/hwangseonu/gin-restful\n```\n\n### Usage Example\nThe following code is a complete example of how to use the gin-restful library to create a simple sample API.\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"strconv\"\n\n\t\"github.com/gin-gonic/gin\"\n\trestful \"github.com/hwangseonu/gin-restful\"\n)\n\n// Define the schema for the request body.\ntype SampleSchema struct {\n\tMessage string `json:\"message\"`\n}\n\nvar offset = 0\n\n// Define the struct that will implement the restful.Resource interface.\ntype Sample struct {\n\tdatabase map[string]SampleSchema\n}\n\n// Returns the schema for the request body.\nfunc (r *Sample) RequestBody(_ string) any {\n\treturn new(SampleSchema)\n}\n\n// Creates a new resource (POST).\nfunc (r *Sample) Create(body interface{}, _ *gin.Context) (gin.H, int, error) {\n\tsample := body.(*SampleSchema)\n\tid := strconv.Itoa(offset)\n\toffset += 1\n\tr.database[id] = *sample\n\n\treturn gin.H{\n\t\t\"message\": sample.Message,\n\t}, http.StatusCreated, nil\n}\n\n// Reads a specific resource (GET).\nfunc (r *Sample) Read(id string, _ *gin.Context) (gin.H, int, error) {\n\tsample, ok := r.database[id]\n\n\tif !ok {\n\t\treturn gin.H{}, 404, nil\n\t} else {\n\t\treturn gin.H{\"message\": sample.Message}, http.StatusOK, nil\n\t}\n}\n\n// Reads all resources (GET).\nfunc (r *Sample) ReadAll(_ *gin.Context) (gin.H, int, error) {\n\tsamples := make(map[string]gin.H)\n\tfor k, v := range r.database {\n\t\tsamples[k] = gin.H{\"message\": v.Message}\n\t}\n\n\treturn gin.H{\n\t\t\"samples\": samples,\n\t}, http.StatusOK, nil\n}\n\n// Updates a specific resource (PUT).\nfunc (r *Sample) Update(id string, body interface{}, _ *gin.Context) (gin.H, int, error) {\n\tsample := body.(*SampleSchema)\n\n\tr.database[id] = *sample\n\n\treturn gin.H{}, http.StatusNoContent, nil\n}\n\n// Deletes a specific resource (DELETE).\nfunc (r *Sample) Delete(id string, _ *gin.Context) (gin.H, int, error) {\n\tdelete(r.database, id)\n\treturn gin.H{}, http.StatusNoContent, nil\n}\n\nfunc main() {\n\t// Initialize the Gin engine and restful API.\n\tengine := gin.Default()\n\tapi := restful.NewAPI(\"/api/v1\")\n\n\t// Create a resource instance.\n\tsample := \u0026Sample{make(map[string]SampleSchema)}\n\n\t// Register the resource routing.\n\tapi.RegisterResource(\"/samples\", sample)\n\tapi.RegisterHandlers(engine)\n\n\t// Run the server.\n\te := engine.Run(\":8080\")\n\tif e != nil {\n\t\tlog.Fatalln(e)\n\t}\n}\n```\n\n### API Endpoints\nThe api.RegisterResource(\"/samples\", sample) line in the example code automatically generates the following RESTful endpoints.\n\n| HTTP Method | Endpoint            | Description                  |\n|:------------| :------------------ | :--------------------------- |\n| `POST`      | `/api/v1/samples`   | Creates a new resource       |\n| `GET`       | `/api/v1/samples`   | Retrieves all resources      |\n| `GET`       | `/api/v1/samples/:id` | Retrieves a specific resource |\n| `PUT`       | `/api/v1/samples/:id` | Updates a specific resource   |\n| `PATCH`     | `/api/v1/samples/:id` | Updates a specific resource   |\n| `DELETE`    | `/api/v1/samples/:id` | Deletes a specific resource   |\n\n## License\nThis project is licensed under the MIT License. See the LICENSE file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwangseonu%2Fgin-restful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhwangseonu%2Fgin-restful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwangseonu%2Fgin-restful/lists"}