{"id":23189360,"url":"https://github.com/ogabrielrodrigues/rest","last_synced_at":"2025-10-07T05:12:16.192Z","repository":{"id":219150001,"uuid":"748303102","full_name":"ogabrielrodrigues/rest","owner":"ogabrielrodrigues","description":"Built-in functions to smooth your programming experience with Chi-Router","archived":false,"fork":false,"pushed_at":"2024-02-06T19:20:35.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-10T13:43:52.440Z","etag":null,"topics":["go","go-chi","http","rest"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/ogabrielrodrigues/rest","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/ogabrielrodrigues.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}},"created_at":"2024-01-25T17:38:35.000Z","updated_at":"2024-01-25T22:41:06.000Z","dependencies_parsed_at":"2024-02-06T20:39:52.752Z","dependency_job_id":null,"html_url":"https://github.com/ogabrielrodrigues/rest","commit_stats":null,"previous_names":["ogabrielrodrigues/rest"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ogabrielrodrigues%2Frest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ogabrielrodrigues%2Frest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ogabrielrodrigues%2Frest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ogabrielrodrigues%2Frest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ogabrielrodrigues","download_url":"https://codeload.github.com/ogabrielrodrigues/rest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294550,"owners_count":20915340,"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":["go","go-chi","http","rest"],"created_at":"2024-12-18T11:18:40.928Z","updated_at":"2025-10-07T05:12:11.153Z","avatar_url":"https://github.com/ogabrielrodrigues.png","language":"Go","readme":"\u003cbr\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\".github/rest.svg\" alt=\"Rest Logo\" /\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"GitHub Release\" src=\"https://img.shields.io/github/v/release/ogabrielrodrigues/rest?display_name=release\"\u003e\n  \u003cimg alt=\"GitHub License\" src=\"https://img.shields.io/github/license/ogabrielrodrigues/rest\"\u003e\n\u003c/div\u003e\n\n\u003ch2\u003eTired of having to do everything by hand every time you start a new go project with the \u003ca href=\"https://github.com/go-chi/chi\" target=\"_blank\"\u003echi\u003c/a\u003e router?\u003c/h3\u003e\n\n\u003cp style=\"font-size: 20px; text-decoration:none;\"\u003eThis set of pre-ready functions will help you save time and make you more productive.\u003c/p\u003e\n\u003cbr\u003e\n\u003cp style=\"font-size: 16px; text-decoration:none;\"\u003e\n  \u003ccode\u003eBinding\u003c/code\u003e\n  \u003cbr\u003e \n  Request body bind and validation with \n  \u003ca href=\"https://github.com/go-playground/validator\" target=\"_blank\"\u003eValidator\u003c/a\u003e.\n\u003c/p\u003e\n\n```go\nimport \"github.com/ogabrielrodrigues/rest\"\n\ntype Body struct {\n  Name string `json:\"name\" validate:\"required,min=2\"`\n  Age int `json:\"age\" validate:\"required,min=1,max=140\"`\n}\n\nfunc ExampleHandler(w http.ResponseWriter, r *http.Request) {\n  body := Body{}\n\n  if err := rest.Bind(r.Body, \u0026body); err != nil {\n    rest.JSON(w, err.Code, err)\n    return\n  }\n\n  // Rest of your handler logic...\n}\n```\n\u003cbr\u003e\n\u003cp style=\"font-size: 16px; text-decoration:none;\"\u003e\n  \u003ccode\u003eError handling\u003c/code\u003e \n  \u003cbr\u003e\n  Better handling of major http status errors.\n\u003c/p\u003e\n\n```go\nimport \"github.com/ogabrielrodrigues/rest\"\n\nfunc ErrorHandler(w http.ResponseWriter, r *http.Request) {\n  rest_error := rest.NewInternalServerErr(\n    \"this error occurred because the logic is not ready\",\n  )\n\n  rest.JSON(w, rest_error.Code, rest_error)\n}\n\n// Output in JSON response:\n{\n  \"message\": \"this error occurred because the logic is not ready\",\n  \"code\": 500,\n  \"error\": \"internal_server_error\"\n}\n```\n\u003cbr\u003e\n\u003cp style=\"font-size: 16px; text-decoration:none;\"\u003e\n  \u003ccode\u003eResponse\u003c/code\u003e \n  \u003cbr\u003e\n  Simple way to return data with \u003ccode\u003eResponseWriter\u003c/code\u003e.\n\u003c/p\u003e\n\n```go\nimport (\n  \"net/http\"\n  \"github.com/ogabrielrodrigues/rest\"\n)\n\nfunc ResponseJSONHandler(w http.ResponseWriter, r *http.Request) {\n  response := map[string]string{\n    \"message\": \"Thank you if you are reading this docs!!\",\n  }\n\n  rest.JSON(w, http.StatusOK, response)\n}\n\n// Output in JSON response:\n{\n  \"message\": \"Thank you if you are reading this docs!!\",\n}\n```\n\n\u003cp style=\"font-size: 16px; text-decoration:none;\"\u003e\n  Or prefer not to return data:\n\u003c/p\u003e\n\n```go\nimport (\n  \"net/http\"\n  \"github.com/ogabrielrodrigues/rest\"\n)\n\nfunc OnlyStatusHandler(w http.ResponseWriter, r *http.Request) {\n  rest.End(w, http.StatusOK)\n}\n\n// Output in response headers:\nHTTP/1.1 200 OK\n```\n\u003cbr\u003e\n\u003cp style=\"font-size: 16px; text-decoration:none;\"\u003e\n  \u003ccode\u003eValidation\u003c/code\u003e \n  \u003cbr\u003e\n  Validate your request body or URL params with\n  \u003ca href=\"https://github.com/go-playground/validator\" target=\"_blank\"\u003eValidator\u003c/a\u003e.\n\u003c/p\u003e\n\n```go\nimport \"github.com/ogabrielrodrigues/rest\"\n\ntype Body struct {\n  Name string `json:\"name\" validate:\"required,min=2\"`\n  Age int `json:\"age\" validate:\"required,min=1,max=140\"`\n}\n\nfunc StructValidationHandler(w http.ResponseWriter, r *http.Request) {\n  body := Body{}\n\n  if err := rest.Validate.Struct(\u0026body); err != nil {\n    rest_error := rest.ValidateStructErr(err)\n    rest.JSON(w, rest_error.Code, rest_error)\n    return\n  }\n\n  // Rest of your handler logic...\n}\n```\n\n\u003cp style=\"font-size: 16px; text-decoration:none;\"\u003e\n  Or validate one URL param:\n\u003c/p\u003e\n\n```go\nimport (\n  \"github.com/go-chi/chi/v5\"\n  \"github.com/ogabrielrodrigues/rest\"\n)\n\nfunc VarValidationHandler(w http.ResponseWriter, r *http.Request) {\n  id := chi.URLParam(r, \"id\")\n\n  if err := rest.Validate.Var(id, \"uuid4\"); err != nil {\n    rest_error := rest.ValidateVarErr(err)\n    rest.JSON(w, rest_error.Code, rest_error)\n    return\n  }\n\n  // Rest of your handler logic...\n}\n```\n\n\u003cbr\u003e\n\u003ch3 align=\"center\" style=\"font-size: 20px; text-decoration:none;\"\u003eMake with ❤️ by \u003ca href=\"https://github.com/ogabrielrodrigues\"\u003eogabrielrodrigues\u003c/a\u003e\u003c/h3\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fogabrielrodrigues%2Frest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fogabrielrodrigues%2Frest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fogabrielrodrigues%2Frest/lists"}