{"id":16728329,"url":"https://github.com/tmc/rest","last_synced_at":"2025-03-15T16:20:55.068Z","repository":{"id":13595618,"uuid":"16288467","full_name":"tmc/rest","owner":"tmc","description":"Small resource-oriented http library","archived":false,"fork":false,"pushed_at":"2014-01-27T18:52:39.000Z","size":136,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-22T06:15:42.674Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmc.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":"2014-01-27T18:37:18.000Z","updated_at":"2019-08-13T15:34:24.000Z","dependencies_parsed_at":"2022-09-10T12:40:26.744Z","dependency_job_id":null,"html_url":"https://github.com/tmc/rest","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/tmc%2Frest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmc%2Frest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmc%2Frest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmc%2Frest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmc","download_url":"https://codeload.github.com/tmc/rest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243754701,"owners_count":20342694,"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":[],"created_at":"2024-10-12T23:09:54.372Z","updated_at":"2025-03-15T16:20:55.045Z","avatar_url":"https://github.com/tmc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rest\n    import \"github.com/tmc/rest\"\n\nPackage rest provides a micro framework for writing json HTTP endpoints\n\nInspiration from dougblack's sleepy\n\nExample:\n\n\n```go\n\tpackage main\n\t\n\timport (\n\t\t\"fmt\"\n\t\t\"io/ioutil\"\n\t\t\"net/http\"\n\t\t\"net/url\"\n\t\n\t\t\"github.com/tmc/rest\"\n\t)\n\t\n\ttype User struct {\n\t\tName string\n\t}\n\t\n\ttype UserRepository struct {\n\t\tusers []User\n\t}\n\t\n\tfunc (ur UserRepository) AllUsers() []User {\n\t\treturn ur.users\n\t}\n\t\n\ttype UserList struct {\n\t\trepo UserRepository\n\t}\n\t\n\tfunc (ul UserList) Get(values url.Values) (int, interface{}) {\n\t\treturn http.StatusOK, ul.repo.AllUsers()\n\t}\n\t\n\tfunc main() {\n\t\ta := rest.API{}\n\t\ta.AddResource(\"/users\", UserList{UserRepository{[]User{{\"joe\"}, {\"sally\"}}}})\n\t\n\t\tgo a.Start(8080)\n\t\n\t\tresp, err := http.Get(\"http://127.0.0.1:8080/users\")\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tdefer resp.Body.Close()\n\t\tbody, err := ioutil.ReadAll(resp.Body)\n\t\n\t\tfmt.Println(resp.Status, string(body))\n        // Output:\n    \t// 200 OK [{\"Name\":\"joe\"},{\"Name\":\"sally\"}]\n\t}\n```\n\n## Constants\n``` go\nconst (\n    GET    = \"GET\"\n    POST   = \"POST\"\n    PUT    = \"PUT\"\n    DELETE = \"DELETE\"\n)\n```\n\n## type API\n``` go\ntype API struct{}\n```\n\n### func (\\*API) Abort\n``` go\nfunc (api *API) Abort(rw http.ResponseWriter, statusCode int)\n```\n\n\n### func (\\*API) AddResource\n``` go\nfunc (api *API) AddResource(path string, resource Resource)\n```\n\n\n### func (\\*API) Start\n``` go\nfunc (api *API) Start(port int)\n```\n\n\n## type BaseResource\n``` go\ntype BaseResource struct{}\n```\n\n\n### func (BaseResource) Delete\n``` go\nfunc (BaseResource) Delete(values url.Values) (int, interface{})\n```\n\n\n### func (BaseResource) Get\n``` go\nfunc (BaseResource) Get(values url.Values) (int, interface{})\n```\n\n\n### func (BaseResource) Post\n``` go\nfunc (BaseResource) Post(values url.Values) (int, interface{})\n```\n\n\n### func (BaseResource) Put\n``` go\nfunc (BaseResource) Put(values url.Values) (int, interface{})\n```\n\n\n## type Resource\n``` go\ntype Resource interface{}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmc%2Frest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmc%2Frest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmc%2Frest/lists"}