{"id":13652531,"url":"https://github.com/bndr/gopencils","last_synced_at":"2025-04-23T03:30:53.196Z","repository":{"id":57489841,"uuid":"21124171","full_name":"bndr/gopencils","owner":"bndr","description":"Easily consume REST APIs with Go (golang)","archived":false,"fork":false,"pushed_at":"2019-02-18T01:03:37.000Z","size":46,"stargazers_count":452,"open_issues_count":7,"forks_count":43,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-12T18:42:09.583Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bndr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-23T11:41:24.000Z","updated_at":"2025-03-05T22:06:07.000Z","dependencies_parsed_at":"2022-08-29T15:12:01.003Z","dependency_job_id":null,"html_url":"https://github.com/bndr/gopencils","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/bndr%2Fgopencils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgopencils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgopencils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgopencils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bndr","download_url":"https://codeload.github.com/bndr/gopencils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250365342,"owners_count":21418670,"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-08-02T02:01:00.174Z","updated_at":"2025-04-23T03:30:52.394Z","avatar_url":"https://github.com/bndr.png","language":"Go","funding_links":[],"categories":["Utilities","公用事业公司","Clients","工具库","工具库`可以提升效率的通用代码库和工具`","实用工具","Service Toolkits","Utility"],"sub_categories":["Advanced Console UIs","实用程序/Miscellaneous","Go Clients","Utility/Miscellaneous","HTTP Clients","交流","查询语","Go","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Fail injection"],"readme":"# Gopencils - Dynamically consume REST APIs\n[![GoDoc](https://godoc.org/github.com/bndr/gopencils?status.svg)](https://godoc.org/github.com/bndr/gopencils)\n[![Build Status](https://travis-ci.org/bndr/gopencils.svg?branch=master)](https://travis-ci.org/bndr/gopencils)\n\n## Summary\nGopencils is a REST Client written in go. Easily consume any REST API's. Supported Response formats: JSON\n\n## Install\n\n    go get github.com/bndr/gopencils\n\n## Simple to use\n\nGopencils was designed to help you easily make requests to REST APIs without much hassle. It supports both Basic-Auth as well as OAuth.\n\nExample Basic-Auth\n\n```go\n\ntype UserExample struct {\n\tId            string\n\tName          string\n\tOrigin        string\n\tUrl           string\n\tSomeJsonField string\n}\n// Create Basic Auth\nauth := gopencils.BasicAuth{\"username\", \"password\"}\n\n// Create New Api with our auth\napi := gopencils.Api(\"http://your-api-url.com/api/\", \u0026auth)\n\n// Create a pointer to our response struct\nresp := \u0026UserExample{}\n\n// Perform a GET request\n// URL Requested: http://your-api-url.com/api/users/1\napi.Res(\"users\", resp).Id(1).Get()\n\n// Get Single Item\napi.Res(\"users\", resp).Id(1).Get()\n\n// Perform a GET request with Querystring\nquerystring := map[string]string{\"page\": \"100\", \"per_page\": \"1000\"}\n\n// URL Requested: http://your-api-url.com/api/users/123/items?page=100\u0026per_page=1000\nresource := api.Res(\"users\").Id(123).Res(\"items\", resp).Get(querystring)\n\n// Now resp contains the returned json object\n// resource.Raw contains raw http response,\n\n// You can supply Path suffix to the api which will be applied to every url\n// e.g /items/id.json\napi := gopencils.Api(\"http://your-api-url.com/api/\", \u0026auth, \".json\")\n\n```\n\nExample Github Api\n\n```go\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/bndr/gopencils\"\n)\n\ntype respStruct struct {\n\tLogin string\n\tId    int\n\tName  string\n}\n\nfunc main() {\n\tapi := gopencils.Api(\"https://api.github.com\")\n\t// Users Resource\n\tusers := api.Res(\"users\")\n\n\tusernames := []string{\"bndr\", \"torvalds\", \"coleifer\"}\n\n\tfor _, username := range usernames {\n\t\t// Create a new pointer to response Struct\n\t\tr := new(respStruct)\n\t\t// Get user with id i into the newly created response struct\n\t\t_, err := users.Id(username, r).Get()\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t} else {\n\t\t\tfmt.Println(r)\n\t\t}\n\t}\n}\n```\nMore examples in the examples folder.\n\n## Why?\nI work a lot with REST APIs and I caught myself writing the same code over and over, so I decided to make a library that would help me (and others) to quickly consume them.\n\n## Is it ready?\n\nIt is still in beta. But I would be glad if you could test it on your pet projects. The API will be improved, but no breaking changes are planned.\n\n## Contribute\n\nAll Contributions are welcome. The todo list is on the bottom of this README. Feel free to send a pull request.\n\n## License\n\nApache License 2.0\n\n## TODO\n1. Add more Options (Flexibility)\n2. Support XML Response\n3. Better Error Handling\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbndr%2Fgopencils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbndr%2Fgopencils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbndr%2Fgopencils/lists"}