{"id":15968560,"url":"https://github.com/smokku/rip","last_synced_at":"2025-04-04T14:25:35.924Z","repository":{"id":24149277,"uuid":"27538894","full_name":"smokku/rip","owner":"smokku","description":"REST.Is.Popular - RESTful microframework for Go","archived":false,"fork":false,"pushed_at":"2020-08-04T08:41:17.000Z","size":13,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T09:53:30.056Z","etag":null,"topics":["go","microframework","rest","rip"],"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/smokku.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-12-04T12:12:32.000Z","updated_at":"2020-08-04T08:41:20.000Z","dependencies_parsed_at":"2022-08-22T09:50:36.034Z","dependency_job_id":null,"html_url":"https://github.com/smokku/rip","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/smokku%2Frip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smokku%2Frip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smokku%2Frip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smokku%2Frip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smokku","download_url":"https://codeload.github.com/smokku/rip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247192287,"owners_count":20899063,"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","microframework","rest","rip"],"created_at":"2024-10-07T19:02:24.048Z","updated_at":"2025-04-04T14:25:35.903Z","avatar_url":"https://github.com/smokku.png","language":"Go","readme":"REST.Is.Popular.\n================\n\n*RESTful microframework for Go*\n\nThere are many REST frameworks for Go Lang (and even more that claim they are), so why write another one?\n\nI needed a skeleton code that simplifies parsing JSON-REST requests and servicn JSON responses. Simple one, that allows me to throw a few lines of code and get some results, but all I got from _The Web_ were behemots requiring me to write gazilions of API descriptors and covering everything including kitchen sink.\n\nThere was one candy though. A [blog article](http://dougblack.io/words/a-restful-micro-framework-in-go.html) that discussed simple matching of HTTP resource methods to Resource object methods. I tried it and it was a pleasure. But after some use I realized its defeciencies and how I could improve on this idea. For once, my API is JSON focused, so auto unmarshalling/marshaling is a must. Secondly, method signatures were a bit cumbersome. Thus RIP was born.\n\n\n## Example\n\nThis example shows [Goji](http://goji.io/) integration, but it is not a must. You can use anything net/http compliant.\n\n```go\nimport (\n\t\"github.com/smokku/rip\"\n\n\t\"github.com/zenazn/goji\"\n\t\"github.com/zenazn/goji/web\"\n\t\"math/rand\"\n\t\"net/http\"\n)\n\n\n// Create a resource and attach HTTP methods handlers\ntype randomResource struct{}\n\nfunc (randomResource) Get(id string, req *http.Request) (int, interface{}, http.Header) {\n\tif len(id) \u003e 0 {\n\t\ti, err := strconv.ParseUint(id, 10, 0)\n\n\t\tif err != nil {\n\t\t\treturn http.StatusBadRequest, err.Error(), nil\n\t\t}\n\n\t\treturn http.StatusOK, rand.Intn(i), nil\n\n\t} else {\n\t\treturn http.StatusNotImplemented, \"Listing all random numbers not implemented\", nil\n\t}\n}\n\n\nfunc main() {\n\t// Create REST API handler and attach resources\n\tapiHandler = rip.New()\n\tapiHandler.Add(\"random\", randomResource{})\n\n\t// Use Goji SubRouter to attach API at /api/*\n\tapi := web.New()\n\tgoji.Handle(\"/api/*\", api)\n\tapi.Use(middleware.SubRouter)\n\tapi.Handle(\"/*\", apiHandler)\n\n\t// Serve static files from public/ just for kicks\n\tgoji.Handle(\"/*\", http.FileServer(http.Dir(\"public\")))\n\n\t// Go, go, go...\n\tgoji.Serve()\n}\n```\n\n    $ curl -i localhost:8000/api/random/100\n\n## Cross-Origin Resource Sharing\n\nOnce you put your API on a separate domain than your main site (or enable it for public use)\nyou will want to setup CORS handling for API requests. Thanks to rs/cors library it is\nmindblowingly simple:\n\n```go\nimport (\n\t\"github.com/smokku/rip\"\n\t//[...]\n\t\"github.com/rs/cors\"\n)\n\nfunc main() {\n\t//[...]\n\tapi1 := web.New()\n\t//[...]\n\tapi1.Use(middleware.SubRouter)\n\tc := cors.New(cors.Options{\n\t\tAllowedOrigins:   []string{\"http://localhost:8080\"},\n\t\tAllowedMethods:   []string{\"GET\", \"POST\", \"PUT\", \"PATH\", \"DELETE\"},\n\t\tAllowedHeaders:   []string{\"accept\", \"content-type\"},\n\t\tAllowCredentials: true,\n\t})\n\tapi1.Use(c.Handler)\n\t//[...]\n}\n```\n\n## Lecture\n\n- [Using HTTP Methods for RESTful Services](http://www.restapitutorial.com/lessons/httpmethods.html)\n\nR.I.P. is inspired by Doug's Black ideas in [blog article](http://dougblack.io/words/a-restful-micro-framework-in-go.html)\nand [sleepy code](https://github.com/dougblack/sleepy).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmokku%2Frip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmokku%2Frip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmokku%2Frip/lists"}