{"id":19727118,"url":"https://github.com/pkbhowmick/go-rest-api","last_synced_at":"2025-04-30T00:32:40.247Z","repository":{"id":55445974,"uuid":"323515764","full_name":"pkbhowmick/go-rest-api","owner":"pkbhowmick","description":"Go REST API Server using Gorilla Mux, Cobra Cli ","archived":false,"fork":false,"pushed_at":"2021-03-11T14:14:44.000Z","size":12143,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T20:34:03.380Z","etag":null,"topics":["golang","http-server","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkbhowmick.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":"2020-12-22T03:59:49.000Z","updated_at":"2024-11-27T09:08:02.000Z","dependencies_parsed_at":"2022-08-15T00:30:37.762Z","dependency_job_id":null,"html_url":"https://github.com/pkbhowmick/go-rest-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkbhowmick%2Fgo-rest-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkbhowmick%2Fgo-rest-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkbhowmick%2Fgo-rest-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkbhowmick%2Fgo-rest-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkbhowmick","download_url":"https://codeload.github.com/pkbhowmick/go-rest-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251607896,"owners_count":21616847,"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","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":["golang","http-server","rest-api"],"created_at":"2024-11-11T23:37:42.152Z","updated_at":"2025-04-30T00:32:39.099Z","avatar_url":"https://github.com/pkbhowmick.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# REST API Server in Golang\n\n- This API server provides endpoints to create,read,update \u0026 delete users and their repositories (like Github).\n  \n[![Go Report Card](https://goreportcard.com/badge/github.com/pkbhowmick/go-rest-api)](https://goreportcard.com/report/github.com/pkbhowmick/go-rest-api)\n\n## To Start API Server\n```$ git clone https://github.com/pkbhowmick/go-rest-api.git```\n\n```$ cd go-rest-api```\n\n```$ go install```\n\n```$ go-rest-api version``` [print the version of the api server]\n\n```$ go-rest-api start```  [run the api server]\n\n## Command to run unit test for API endpoints\n```$ cd api```\n\n```$ go test```\n\n## Commands to run API server in docker container\n```shell\n$ docker build -t \u003cimage_name\u003e .\n$ docker run -p 8080:8080 \u003cgiven_image_name\u003e # to start the server with default config\n$ docker run -p 8080:8080 \u003cgiven_image_name\u003e start -a=false # to start the server without authentication\n```\n\n## Commands to pull image from docker hub and run locally\n```shell\n$ docker pull pkbhowmick/go-rest-api\n$ docker run -p 8080:8080 pkbhowmick/go-rest-api # to start the server with default config\n$ docker run -p 8080:8080 pkbhowmick/go-rest-api start -a=false # to start the server without authentication\n```\n\n\n## Data Model\n\n- User Model\n``````\ntype User struct {\n\tID           string       `json:\"id\"`\n\tFirstName    string       `json:\"firstName\"`\n\tLastName     string       `json:\"lastName\"`\n\tRepositories []Repository `json:\"repositories\"`\n\tCreatedAt    time.Time    `json:\"createdAt\"`\n}\n``````\n- Repository Model\n``````\ntype Repository struct {\n\tID         string    `json:\"id\"`\n\tName       string    `json:\"name\"`\n\tVisibility string    `json:\"visibility\"`\n\tStar       int       `json:\"star\"`\n}\n``````\n\n## Available API Endpoints\n\n|  Method | API Endpoint  | Authentication Type | Description |\n|---|---|---|---|\n|POST| /api/login | Basic | Return jwt token in response for successful authentication\n|GET| /api/users | Basic or Bearer token | Return a list of all users in response| \n|GET| /api/users/{id} | Basic or Bearer token| Return the data of given user id in response| \n|POST| /api/users | Basic or Bearer token |Add an user in the database and return the added user data in response | \n|PUT| /api/users/{id} | Basic or Bearer token |Update the user and return the updated user info in response| \n|DELETE| /api/users/{id} | Basic or Bearer token |Delete the user and return the deleted user data in response| \n\n## Available Flags\n\n| Flag | Shorthand | Default value | Example | Description\n|---|---|---|---|---|\n|port|p|8080| go-rest-api start --port=8090 | Start API server in the given port otherwise in default port\n|auth|a|true| go-rest-api start --auth=false | If true impose authentication on API server otherwise bypass it\n\n## Environment Variables\n\n| Name | Default(in docker image) | Description\n|---|---|---|\nADMIN_USER | admin | API server admin username\nADMIN_PASS | demo | API server admin password\nSIGNING_KEY | veryverysecretkey | API server jwt token signing key\n\n\n## Sample Curl commands without authentication\n\nRun API server without authentication\n\n```shell\n$ go-rest-api start --port=8080 --auth=false\n``` \n\nGet all users information\n\n```shell\n$ curl -X GET http://localhost:8080/api/users\n``` \n\nGet user information with id 1\n\n```shell\n$ curl -X GET http://localhost:8080/api/users/1\n```\n\nCreate user with given id\n\n```shell\n$ curl -X POST  -H \"Content-Type:application/json\" -d '{\"id\":\"6\",\"firstName\":\"testfirst\",\"lastName\":\"testlast\"}' http://localhost:8080/api/users\n``` \n\nModify user data with gigen id\n\n```shell\n$ curl -X PUT  -H \"Content-Type:application/json\" -d '{\"firstName\":\"test\",\"lastName\":\"test\"}' http://localhost:8080/api/users/1\n``` \n\nDelete user with given id\n\n```shell\n$ curl -X DELETE http://localhost:8080/api/users/1\n``` \n\n## Sample Curl commands with Basic authentication\n\n```shell\n$ export ADMIN_USER=admin\n```\n\n```shell\n$ export ADMIN_PASS=demo\n```\n\nRun API server with authentication\n\n```shell\n$ go-rest-api start --port=8080 --auth=true\n``` \n\nGet all users information\n\n```shell\n$ curl -X GET --user admin:demo http://localhost:8080/api/users\n``` \n\nGet user information with id 1\n\n```shell\n$ curl -X GET --user admin:demo http://localhost:8080/api/users/1\n``` \n\nCreate user with given id\n\n```shell\n$ curl -X POST  --user admin:demo -H \"Content-Type:application/json\" -d '{\"id\":\"6\",\"firstName\":\"testfirst\",\"lastName\":\"testlast\"}' http://localhost:8080/api/users\n``` \n\nModify user data with given id\n\n```shell\n$ curl -X PUT  --user admin:demo -H \"Content-Type:application/json\" -d '{\"firstName\":\"test\",\"lastName\":\"test\"}' http://localhost:8080/api/users/1\n``` \n\nDelete user with given id\n\n```shell\n$ curl -X DELETE --user admin:demo http://localhost:8080/api/users/1\n``` \n\n## Sample Curl commands with Bearer token(JWT token) authentication\n\n```shell\n$ export ADMIN_USER=admin\n```\n\n```shell\n$ export ADMIN_PASS=demo\n```\n\n```shell\n$ export SIGNING_KEY=veryverysecretkey\n```\n\nRun API server with authentication\n\n```shell\n$ go-rest-api start --port=8080 --auth=true\n``` \n\nGet jwt token via login with basic authentication\n\n```shell\n$ curl -X POST --user admin:demo  http://localhost:8080/api/login\n``` \n\nGet all users information\n\n```shell\n$ curl -X GET -H \"Authorization: Bearer \u003cjwt_token\u003e\"  http://localhost:8080/api/users\n``` \n\nGet user information with id 1\n\n```shell\n$ curl -X GET -H \"Authorization: Bearer \u003cjwt_token\u003e\" http://localhost:8080/api/users/1\n``` \n\nCreate user with given id\n\n```shell\n$ curl -X POST -H \"Authorization: Bearer \u003cjwt_token\u003e\" -H \"Content-Type:application/json\" -d '{\"id\":\"6\",\"firstName\":\"testfirst\",\"lastName\":\"testlast\"}' http://localhost:8080/api/users\n``` \n\nModify user data with given id\n\n```shell\n$ curl -X PUT -H \"Authorization: Bearer \u003cjwt_token\u003e\" -H \"Content-Type:application/json\" -d '{\"firstName\":\"test\",\"lastName\":\"test\"}' http://localhost:8080/api/users/1 \n``` \n\nDelete user with given id\n\n```shell\n$ curl -X DELETE -H \"Authorization: Bearer \u003cjwt_token\u003e\" http://localhost:8080/api/users/1\n``` ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkbhowmick%2Fgo-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkbhowmick%2Fgo-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkbhowmick%2Fgo-rest-api/lists"}