{"id":26115610,"url":"https://github.com/andreistefanciprian/go_rest_api_demo","last_synced_at":"2025-10-15T10:46:43.426Z","repository":{"id":61848989,"uuid":"538034026","full_name":"andreistefanciprian/go_rest_api_demo","owner":"andreistefanciprian","description":"Explore building a CRUD REST API and frontend UI in Go","archived":false,"fork":false,"pushed_at":"2022-10-28T11:59:55.000Z","size":125,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-13T10:49:24.925Z","etag":null,"topics":["golang","jwt","jwt-authentication","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreistefanciprian.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":"2022-09-18T07:28:59.000Z","updated_at":"2022-11-23T23:46:55.000Z","dependencies_parsed_at":"2023-01-20T14:47:27.343Z","dependency_job_id":null,"html_url":"https://github.com/andreistefanciprian/go_rest_api_demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andreistefanciprian/go_rest_api_demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fgo_rest_api_demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fgo_rest_api_demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fgo_rest_api_demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fgo_rest_api_demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreistefanciprian","download_url":"https://codeload.github.com/andreistefanciprian/go_rest_api_demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreistefanciprian%2Fgo_rest_api_demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279074518,"owners_count":26097646,"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-15T02:00:07.814Z","response_time":56,"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":["golang","jwt","jwt-authentication","rest-api"],"created_at":"2025-03-10T07:56:12.260Z","updated_at":"2025-10-15T10:46:43.390Z","avatar_url":"https://github.com/andreistefanciprian.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Description\n\nEasy REST API backend and Bootstrap frontend written in Golang using standard libraries.\nThe backend exposes CRUD (Create, Read, Update and Delete) endpoints to allow accessing and manipulating articles in a library stored in mysql db. \n\n![Alt text](/img.png \"Frontend Screenshot\")\n\n## API Specification (backend)\n\nThe operations that our endpoint will allow include:\n* **Create** a new article in response to a valid POST request at /article/create.\n* **Fetch** an article in response to a valid GET request at /article/view?id={id}.\n* **Fetch** a list of all articles in response to a valid GET request at /articles.\n* **Update** an article in response to a valid PUT request at /article/update?id={id}.\n* **Delete** an article in response to a valid DELETE request at /article/delete?id={id}.\n\nUsed Go libraries:\n* net/http (standard library for using web servers)\n* gorm (mysql ORM)\n* encoding/json (for transforming data from go struct to json and vice versa)\n* jwt-go (for authenticating requests with JWT tokens)\n\n## Frontend\n\nI'm using https://getbootstrap.com/ to have a nice user interface without going deep on CSS, JS and HTML.\n\nUsed Go libraries:\n* net/http\n* html/template\n\n## Requirements\n\n* Golang (for writing the application code)\n* Docker (for packaging and running the application)\n* Any browser\n* https://jwt.io/ for generating jwt tokens\n\n## Run app with docker-compose\n\n```\n# start app\ndocker-compose up --build\n\n# stop app\ndocker-compose down\n\n# access frontend at localhost:8090/\n```\n\n## (Optional) Test REST API endpoints with curl or Postman\n\n###### Generate jwt token with https://jwt.io/\nMake sure you use the same secret key (JWT_SECRET_KEY) to generate a valid JWT token.\n```\nexport JWT_TOKEN=\"\u003cpaste here jwt token\u003e\"\n```\n\n###### Get all articles\n```\ncurl -X GET http://localhost:8080/articles \\\n-H 'Content-Type: application/json' \\\n-H \"Token:$JWT_TOKEN\" \n```\n\n###### Create new article\n```\ncurl -X POST http://localhost:8080/article/create \\\n-H 'Content-Type: application/json' \\\n-H \"Token:$JWT_TOKEN\" \\\n-d '''\n{\n    \"Title\": \"Book Title\",\n    \"desc\": \"Book Description\",\n    \"content\": \"Book Content\"\n}\n'''\n```\n\n###### View article by id\n```\ncurl -X GET 'http://localhost:8080/article/view?id=32' \\\n-H 'Content-Type: application/json' \\\n-H \"Token:$JWT_TOKEN\"\n```\n\n###### Update article by id\n```\ncurl -X POST 'http://localhost:8080/article/update?id=32' \\\n-H 'Content-Type: application/json' \\\n-H \"Token:$JWT_TOKEN\"\n-d '''\n{\n    \"Title\": \"Updated Book Title\",\n    \"desc\": \"Book Description\",\n    \"content\": \"Book Content\"\n}\n'''\n```\n\n###### Delete article by id\n```\ncurl -X POST 'http://localhost:8080/article/delete?id=32' \\\n-H \"Token:$JWT_TOKEN\"\n```\n\n###### Delete all articles\n```\ncurl -X POST 'http://localhost:8080/articles/delete_all' \\\n-H \"Token:$JWT_TOKEN\" \n```\n\n## Debug commands\n\n```\ndocker network ls\ndocker run --network go_rest_api_demo_demo -it --rm --name mysql-client mysql \\\nmysql -hmy_db -udemouser -pdemopassword -e \"SELECT * from quickdemo.articles;\"\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreistefanciprian%2Fgo_rest_api_demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreistefanciprian%2Fgo_rest_api_demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreistefanciprian%2Fgo_rest_api_demo/lists"}