{"id":18494811,"url":"https://github.com/gbrlsnchs/rest","last_synced_at":"2025-06-11T14:07:42.453Z","repository":{"id":57582299,"uuid":"153675371","full_name":"gbrlsnchs/rest","owner":"gbrlsnchs","description":"RESTful HTTP handler for Go","archived":false,"fork":false,"pushed_at":"2018-10-24T18:19:57.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T22:56:52.088Z","etag":null,"topics":["go","golang","http","http-handler","rest","restful"],"latest_commit_sha":null,"homepage":null,"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/gbrlsnchs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-10-18T19:15:54.000Z","updated_at":"2018-10-24T18:19:59.000Z","dependencies_parsed_at":"2022-09-26T19:32:30.126Z","dependency_job_id":null,"html_url":"https://github.com/gbrlsnchs/rest","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Frest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Frest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Frest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Frest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gbrlsnchs","download_url":"https://codeload.github.com/gbrlsnchs/rest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Frest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259280073,"owners_count":22833420,"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","http-handler","rest","restful"],"created_at":"2024-11-06T13:22:16.020Z","updated_at":"2025-06-11T14:07:42.413Z","avatar_url":"https://github.com/gbrlsnchs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rest (RESTful HTTP handler for Go)\n\n[![Build Status](https://travis-ci.org/gbrlsnchs/rest.svg?branch=master)](https://travis-ci.org/gbrlsnchs/rest)\n[![Sourcegraph](https://sourcegraph.com/github.com/gbrlsnchs/rest/-/badge.svg)](https://sourcegraph.com/github.com/gbrlsnchs/rest?badge)\n[![GoDoc](https://godoc.org/github.com/gbrlsnchs/rest?status.svg)](https://godoc.org/github.com/gbrlsnchs/rest)\n[![Minimal Version](https://img.shields.io/badge/minimal%20version-go1.10%2B-5272b4.svg)](https://golang.org/doc/go1.10)\n\n## About\nThis package implements a simple RESTful HTTP handler that facilitates receiving requests or sending responses in JSON or XML by using a custom context.\n\n## Usage\nFull documentation [here](https://godoc.org/github.com/gbrlsnchs/rest).\n\n### Installing\n#### Go 1.10\n`vgo get -u github.com/gbrlsnchs/rest`\n#### Go 1.11 or after\n`go get -u github.com/gbrlsnchs/rest`\n\n### Importing\n```go\nimport (\n\t// ...\n\n\t\"github.com/gbrlsnchs/rest\"\n)\n```\n\n### Setting a wrapper\n#### Consider the following type to be received / sent\n```go\ntype message struct {\n\tcontent string `json:\"content,omitempty\"`\n}\n```\n\n#### Now, set the main handler\n```go\nhttp.Handle(\"/\", \u0026rest.Wrapper{\n\tHandler: rest.HandlerFunc(func(ctx *rest.Context) {\n\t\tvar ping message\n\t\tif err := ctx.ReceiveJSON(\u0026ping); err != nil {\n\t\t\t// handle error\n\t\t}\n\t\tif ping.content != \"ping\" {\n\t\t\tctx.Send(http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\t\tpong := message{\"pong\"}\n\t\tctx.SendJSON(pong, http.StatusOK)\n\t}),\n\tRecoverHandler: rest.HandlerFunc(func(ctx *rest.Context) {\n\t\tctx.Send(http.StatusInternalServerError)\n\t}),\n})\n```\n\n## Contributing\n### How to help\n- For bugs and opinions, please [open an issue](https://github.com/gbrlsnchs/rest/issues/new)\n- For pushing changes, please [open a pull request](https://github.com/gbrlsnchs/rest/compare)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbrlsnchs%2Frest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgbrlsnchs%2Frest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbrlsnchs%2Frest/lists"}