{"id":20169114,"url":"https://github.com/shikha-code36/golang-crud-rest-api-gin","last_synced_at":"2026-05-08T21:35:17.203Z","repository":{"id":234906635,"uuid":"789720728","full_name":"Shikha-code36/golang-crud-rest-api-gin","owner":"Shikha-code36","description":"Implementation of REST-API's in GoLang using GIN","archived":false,"fork":false,"pushed_at":"2024-04-21T16:29:46.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T09:56:08.874Z","etag":null,"topics":["gin","gin-framework","gin-gonic","gin-restful","gin-restful-api","go","go-gin","go-gin-app","go-rest-api","go-restful","golang","golang-tutorial","golang-tutorials"],"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/Shikha-code36.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}},"created_at":"2024-04-21T11:23:53.000Z","updated_at":"2024-04-21T16:32:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"8cc3b582-c56c-4936-b6cd-bd68a38afe88","html_url":"https://github.com/Shikha-code36/golang-crud-rest-api-gin","commit_stats":null,"previous_names":["shikha-code36/golang-crud-rest-api-gin"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Shikha-code36/golang-crud-rest-api-gin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shikha-code36%2Fgolang-crud-rest-api-gin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shikha-code36%2Fgolang-crud-rest-api-gin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shikha-code36%2Fgolang-crud-rest-api-gin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shikha-code36%2Fgolang-crud-rest-api-gin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shikha-code36","download_url":"https://codeload.github.com/Shikha-code36/golang-crud-rest-api-gin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shikha-code36%2Fgolang-crud-rest-api-gin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32798623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"ssl_error","status_checked_at":"2026-05-08T08:22:45.650Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["gin","gin-framework","gin-gonic","gin-restful","gin-restful-api","go","go-gin","go-gin-app","go-rest-api","go-restful","golang","golang-tutorial","golang-tutorials"],"created_at":"2024-11-14T01:11:26.178Z","updated_at":"2026-05-08T21:35:17.188Z","avatar_url":"https://github.com/Shikha-code36.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang CRUD REST API with Gin\n\nThis is a simple CRUD (Create, Read, Update, Delete) REST API in Go using the Gin web framework.\n\nBefore learning about implementation of REST API in Go using GIN, I suggest learn the basics of GO first.\nCheckout the repository [here](https://github.com/Shikha-code36/golang-tutorial-practice) to learn about the basic implementation in GO.\n\n## Getting Started\n\nFollow these instructions to get a copy of the project up and running on your local machine.\n\n### Prerequisites\n\n- Go (at least version 1.11)\n\n### Cloning the Project\n\n```bash\ngit clone https://github.com/Shikha-code36/golang-crud-rest-api-gin.git\ncd golang-crud-rest-api-gin\n```\n\n### Initializing the Project\n\n```bash\ngo mod init github.com/Shikha-code36/golang-crud-rest-api-gin\n```\n\n### Downloading Dependencies\n\n```bash\ngo mod tidy\n```\n\n## Running the Application\n\n```bash\ngo run main.go\n```\n\nThe application will start running at `http://localhost:8080`.\n\n## Explanation of Code\n\n### main.go\n\nThe `main.go` file is the entry point of our application. Here's a breakdown of its structure and functionality:\n\n```go\npackage main\n```\nThis line defines the package that this file belongs to. In Go, the `main` package is special. It's the entry point of the application, and it must contain a `main` function.\n\n```go\nimport (\n    \"github.com/gin-gonic/gin\"\n    \"github.com/Shikha-code36/golang-crud-rest-api-gin/handlers\"\n)\n```\nThis block imports two packages. The first one, `github.com/gin-gonic/gin`, is the Gin web framework that we're using to build our API. The second one, `github.com/Shikha-code36/golang-crud-rest-api-gin/handlers`, is the package that contains our handler functions.\n\n```go\nfunc main() {\n    r := gin.Default()\n```\nThis is the `main` function where our application starts. `gin.Default()` creates a new Gin engine with some default middleware (logger and recovery). This engine is used to set up our routes and start the server.\n\n```go\n    r.GET(\"/users\", handlers.GetUsers)\n    r.GET(\"/user/:id\", handlers.GetUser)\n    r.POST(\"/create_user\", handlers.CreateUser)\n    r.PUT(\"/update_user/:id\", handlers.UpdateUser)\n    r.DELETE(\"/delete_user/:id\", handlers.DeleteUser)\n```\nThese lines define our API routes. For each route, we specify an HTTP method (GET, POST, PUT, DELETE), a path, and a handler function. When a request is received that matches a route's method and path, the corresponding handler function is called.\n\n```go\n    r.Run()\n}\n```\nFinally, `r.Run()` starts the Gin server and begins listening for requests. By default, it listens on `localhost:8080`, but you can pass a different address as an argument to `Run` if you want.\n\nThat's the basic structure of our `main.go` file. It sets up our server, defines our routes, and starts the server.\n\n### users.go in handlers\n\nThe `users.go` file in the `handlers` directory contains the handler functions for our routes. You can find the detailed explanation [here](handlers).\n\n## API Endpoints\n\n- **GET /users**: Fetch all users.\n- **GET /user/:id**: Fetch a user by ID.\n- **POST /create_user**: Create a new user. The request body should be a JSON object with a `name` field, like this: `{\"name\": \"Alice\"}`. The ID will be assigned automatically.\n- **PUT /update_user/:id**: Update a user by ID. The request body should be a JSON object with a `name` field, like this: `{\"name\": \"Bob\"}`.\n- **DELETE /delete_user/:id**: Delete a user by ID.\n\n## Testing the API\n\nYou can use a tool like curl or Postman to test the API. Here are some examples:\n\n- Fetch all users:\n\n```bash\ncurl -X GET http://localhost:8080/users\n```\n\n- Fetch a user by ID:\n\n```bash\ncurl -X GET http://localhost:8080/user/1\n```\n\n- Create a new user:\n\n```bash\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"name\":\"Alice\"}' http://localhost:8080/create_user\n```\n\n- Update a user by ID:\n\n```bash\ncurl -X PUT -H \"Content-Type: application/json\" -d '{\"name\":\"Bob\"}' http://localhost:8080/update_user/1\n```\n\n- Delete a user by ID:\n\n```bash\ncurl -X DELETE http://localhost:8080/delete_user/1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshikha-code36%2Fgolang-crud-rest-api-gin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshikha-code36%2Fgolang-crud-rest-api-gin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshikha-code36%2Fgolang-crud-rest-api-gin/lists"}