{"id":20314733,"url":"https://github.com/martin3zra/responder","last_synced_at":"2026-05-29T01:31:41.956Z","repository":{"id":65471139,"uuid":"268835073","full_name":"martin3zra/responder","owner":"martin3zra","description":"Wrapper for http responses","archived":false,"fork":false,"pushed_at":"2023-02-17T02:53:51.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T12:49:50.583Z","etag":null,"topics":["go","golang","http"],"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/martin3zra.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":"2020-06-02T15:14:45.000Z","updated_at":"2023-01-24T20:32:41.000Z","dependencies_parsed_at":"2024-06-21T11:56:29.341Z","dependency_job_id":"4f9e987a-98d6-4e08-a71a-a05dcde88113","html_url":"https://github.com/martin3zra/responder","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"6458a68dc7ad2b9d48ea80d15935c777ec53e1a7"},"previous_names":["martin3zra/respond"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin3zra%2Fresponder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin3zra%2Fresponder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin3zra%2Fresponder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin3zra%2Fresponder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martin3zra","download_url":"https://codeload.github.com/martin3zra/responder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241818877,"owners_count":20025210,"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","golang","http"],"created_at":"2024-11-14T18:16:31.386Z","updated_at":"2026-05-29T01:31:36.923Z","avatar_url":"https://github.com/martin3zra.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Responder\n\nWrapper in top of [http package](https://golang.org/pkg/net/http/).\n\n## Install\n\nYou might as well just copy the [responder.go](https://github.com/martin3zra/responder/blob/master/responder.go) file into your own project (and the [responder_test.go](https://github.com/martin3zra/respond/blob/master/responder_test.go) while you're at it for future generations) rather than adding a dependency.\n\nBut it is maintained as a Go module which you can get with:\n\n```bash\ngo get github.com/martin3zra/responder\n```\n\n## Usage\n\nImport it:\n\n```go\nimport (\n\t\"github.com/martin3zra/responder\"\n)\n```\n\nThe package will show you a clean way and guide you through the necessary steps to respond from your handlers.\n\n```go\nfunc (w http.ResponseWriter, r *http.Request) {\n\t//do your thing and respond\n\tdata := map[string]interface{}{\n\t\t\"customer\": \"...\"\n\t}\n\n\trespond := responder.New(w)\n\trespond.OK(data)\n\n\t// If you whish to flash any data\n\trespond.With(\"error\", \"resource can not be created!\").OK(data)\n}\n\n// without flashing data\n{\n  \"data\": {\"customer\": \"...\"},\n  \"flash\": {\n\t\"success\": nil,\n\t\"error\": nil\n  },\n}\n\n// Flashing data\n{\n  \"data\": {\"customer\": \"...\"},\n  \"flash\": {\n\t\"success\": nil,\n\t\"error\": \"resource can not be created!\",\n  }\n}\n```\n\nIn this example, we would respond with `http.StatusOK`, content-type of `application/json` and will write the data to the buffer.\n\nPlease check the [respond_test.go](https://github.com/martin3zra/responder/blob/master/responder_test.go) for more samples.\n\nWe also add a **_error formatter_** interface so you can add more information and custom code for your projects. You only have to implement his methods `Code`, `Error` and this other one that are optional `Description` and `InfoURL`\n\nwe also an **_error formatter_** [error.go](https://github.com/martin3zra/responder/blob/master/error.go) interface so you can add more information and custom code for your project errors. You only have to implement his methods `Code`, `Error`, `Description`, `InfoURL`. The interface implements from the core [errors pkg](https://golang.org/pkg/errors/) interface.\n\n```go\ntype NotFound struct {}\n\nfunc (NotFound) Status() int {\n    return http.StatusNotFound\n}\n\nfunc (NotFound) Code() int {\n\treturn 40401\n}\n\nfunc (NotFound) Error() string {\n\treturn \"resource not found\"\n}\n\nfunc (NotFound) Description() *string {\n\ts := \"resource not found long description\"\n\treturn \u0026s\n}\n\nfunc (NotFound) InfoURL() *string {\n\ts := \"resource not found URL\"\n\treturn \u0026s\n}\n\n//Then when you use any of the respond alias just have to pass the\nNotFound struct as parameter, and the output will be next one.\n\n{\n  \"code\": 41,\n  \"message\": \"Invalid credentials\",\n  \"description\": \"The requested service needs valid credentials\",\n  \"info_url\": \"https://url.com/to-your-errors-table/41\"\n}\n```\n\nAs the methods `Description` and `InfoURL` are optional the resolver will ignore them when they are `nil`. But you can be embedded to avoid create these methods directly in your custom error.\n\n```go\ntype NotFound struct {\n\trespond.ErrorDescriptor\n}\n\n//If you want a specific status code just implement Status()\nfunc (NotFound) Status() int {\n    return http.StatusNotFound\n}\n\nfunc (NotFound) Code() int {\n\treturn 40401\n}\n\nfunc (NotFound) Error() string {\n\treturn \"resource not found\"\n}\n\n//Then when you use any of the respond alias just have to pass the\nNotFound struct as parameter, and the output will be next one.\n\n{\n  \"code\": 41,\n  \"message\": \"Invalid credentials\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartin3zra%2Fresponder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartin3zra%2Fresponder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartin3zra%2Fresponder/lists"}