{"id":15674635,"url":"https://github.com/olebedev/rest","last_synced_at":"2025-09-25T09:35:56.062Z","repository":{"id":13183089,"uuid":"15866492","full_name":"olebedev/rest","owner":"olebedev","description":"REST interface over MongoDB, as middlware for martini framework.","archived":false,"fork":false,"pushed_at":"2014-04-18T15:48:22.000Z","size":270,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-06T23:28:33.779Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olebedev.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-13T11:39:52.000Z","updated_at":"2018-04-03T23:02:45.000Z","dependencies_parsed_at":"2022-09-10T22:52:04.459Z","dependency_job_id":null,"html_url":"https://github.com/olebedev/rest","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/olebedev/rest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Frest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Frest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Frest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Frest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olebedev","download_url":"https://codeload.github.com/olebedev/rest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Frest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276896496,"owners_count":25724047,"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","status":"online","status_checked_at":"2025-09-25T02:00:09.612Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-03T15:48:41.006Z","updated_at":"2025-09-25T09:35:56.025Z","avatar_url":"https://github.com/olebedev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## REST \n\n[![wercker status](https://app.wercker.com/status/2cc7a63877f6403e5367142f950b2145/s/ \"wercker status\")](https://app.wercker.com/project/bykey/2cc7a63877f6403e5367142f950b2145) [![GoDoc](https://godoc.org/github.com/olebedev/rest?status.png)](https://godoc.org/github.com/olebedev/rest)\n\nSimple [REST](http://en.wikipedia.org/wiki/Representational_state_transfer) interface over MongoDB, as middlware for [martini](https://github.com/go-martini/martini) framework. Useful to create single page applications, REST style based.\n\n#### Usage:\n\n```go\npackage main\n\nimport (\n  \"github.com/go-martini/martini\"\n  \"labix.org/v2/mgo\"\n  \"github.com/olebedev/rest\"\n)\n\nfunc access(res http.ResponseWriter, req *http.Request){\n  // Your data access logic here\n}\n\nfunc main() {\n  session, err := mgo.Dial(\"localhost\")\n  if err != nil {\n    panic(err)\n  }\n  defer session.Close()\n  session.SetMode(mgo.Monotonic, true)\n  db := session.DB(\"test\")\n\n  m := martini.Classic()\n  \n  m.Group(\"/api/v1\", rest.Rest(rest.Config{\n    Db:           db, \n    ResonseField: \"data\", // optional\n    // Use integer autoincrement for _id instead of mongodb auto generated hash, default false. optional\n    // Autoincrement: true, \n  }, access))\n\n  m.Run()\n}\n```\n\nNow you can send HTTP requests to `http://localhost:3000/api/v1/example_collection`.  \nAvailable `GET` parameters:  \n\n- query - JSON mongodb [query](http://www.mongodb.org/display/DOCS/Querying) statement\n- limit - `int`\n- skip - `int`\n- sort - `string`, [more detail](http://godoc.org/labix.org/v2/mgo#Query.Sort)\n- count - `bool`\n- select - JSON mongodb [select](http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields) statement\n\n#### Examples:\n\nLet's create something simple.\n```bash\n$ curl -X POST http://localhost:5000/api/v1/test -s \\\n  -H \"Accept: application/json\" \\\n  -H \"Content-type: application/json\" \\\n  -d '{\"hello\":\"world\"}'\n\n{\n  \"data\": { // ResonseField name\n    \"_id\":\"52d382ae367e0ee611626bf1\"\n    \"hello\":\"world\"\n  }\n}\n$ // ... and so on\n```\n\nTo get full collection use this command:\n```bash\n$ curl http://localhost:5000/api/v1/test\n{\n  \"data\": [\n    {\n      \"hello\": \"world\",\n      \"_id\": \"52d382ae367e0ee611626bf0\"\n    },\n    {\n      \"hello\": \"world 2\",\n      \"_id\": \"52d382b0367e0ee611626bf1\"\n    },\n    {\n      \"hello\": \"world 3\",\n      \"_id\": \"52d382b4367e0ee611626bf2\"\n    }\n  ]\n}\n```\n\nAlso available PUT(by id) \u0026 DELETE(by id) methods.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folebedev%2Frest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folebedev%2Frest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folebedev%2Frest/lists"}