{"id":13786665,"url":"https://github.com/edermanoel94/rest-go","last_synced_at":"2026-01-12T12:57:56.465Z","repository":{"id":144201171,"uuid":"199510425","full_name":"edermanoel94/rest-go","owner":"edermanoel94","description":"A package that provide many helpful methods for working with rest api.","archived":false,"fork":false,"pushed_at":"2020-08-16T04:57:53.000Z","size":84,"stargazers_count":16,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-22T13:32:26.755Z","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/edermanoel94.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-07-29T18:56:08.000Z","updated_at":"2022-09-27T09:53:28.000Z","dependencies_parsed_at":"2023-06-18T12:19:05.466Z","dependency_job_id":null,"html_url":"https://github.com/edermanoel94/rest-go","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/edermanoel94%2Frest-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edermanoel94%2Frest-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edermanoel94%2Frest-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edermanoel94%2Frest-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edermanoel94","download_url":"https://codeload.github.com/edermanoel94/rest-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253645311,"owners_count":21941314,"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-03T19:01:27.538Z","updated_at":"2026-01-12T12:57:56.459Z","avatar_url":"https://github.com/edermanoel94.png","language":"Go","funding_links":[],"categories":["Utilities","工具库","工具库`可以提升效率的通用代码库和工具`","Utility","公用事业公司"],"sub_categories":["HTTP Clients","Utility/Miscellaneous","查询语","Fail injection","实用程序/Miscellaneous"],"readme":"Rest GO - Helpful library for Rest API\n======================================\n\n[![Build Status](https://travis-ci.org/edermanoel94/rest-go.svg?branch=master)](https://travis-ci.org/edermanoel94/rest-go)\n[![eder](https://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/edermanoel94/rest-go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/edermanoel94/rest-go)](https://goreportcard.com/report/github.com/edermanoel94/rest-go)\n[![codecov](https://codecov.io/gh/edermanoel94/rest-go/branch/master/graph/badge.svg)](https://codecov.io/gh/edermanoel94/rest-go)\n\nA package that provide many helpful methods for working with rest api.\n\nAnd if u are tired of written, this:\n\n```go\n\nfunc SomeHandler(w http.ResponseWriter, r *http.Request) {\n\n    w.Header().Add(\"Content-Type\", \"application/json\")\n\n    product := \u0026product{\"Smart TV\", 50.00}\n    \n    bytes, err := json.Marshal(product)\n    \n    if err != nil {\n    \tw.WriteHeader(http.StatusInternalServerError)\n        // this is super bad!\n        message := fmt.Sprintf(`{\"message\": \"%s\"}`, err.Error())\n    \tw.Write([]byte(message))\n        return\n    }\n    \n    w.WriteHeader(http.StatusOk)\n    w.Write(bytes)\n}\n```\n\nGet started:\n\n  * Install rest GO with [one line of code](#installation)\n\n\n[`rest`](http://godoc.org/github.com/edermanoel94/rest-go \"API documentation\") package\n-------------------------------------------------------------------------------------------\n\nThe `rest` package provides some helpful methods that allow you to write better rest api in GO.\n\n  * Allows for very readable code\n\nSee it in action:\n\n```go\npackage yours\n\nimport (\n    \"github.com/edermanoel94/rest-go\"\n    \"net/http\"\n)\n\ntype product struct {\n    Name  string `json:\"name\"`\n    Price float32 `json:\"price\"`\n}\n\nfunc SomeHandler(w http.ResponseWriter, r *http.Request) {\n    rest.Marshalled(w, \u0026product{\"Smart TV\", 50.00}, http.StatusOK)\n}\n```\n\nA payload send to your API and desarialize to a struct, to easy!\n\n```go\npackage yours\n\nimport (\n    \"github.com/edermanoel94/rest-go\"\n    \"net/http\"\n)\n\ntype product struct {\n    Name  string `json:\"name\"`\n    Price float32 `json:\"price\"`\n}\n\n// [POST] body: {\"name\": \"eder\", \"price\": 20.00}\nfunc SomePostHandler(w http.ResponseWriter, r *http.Request) {\n\n    product := product{}\n    err := rest.GetBody(r.Body, \u0026product)\n    if err != nil {\n        // do stuff with error\n    }\n    // Do stuff...\n}    \n```\n\nWorking with [`mux`](https://github.com/gorilla/mux \"API documentation\") package to check if path variable exist.\n\n```go\npackage yours\n\nimport (\n    \"github.com/edermanoel94/rest-go\"\n    \"github.com/gorilla/mux\"\n    \"net/http\"\n)\n\ntype product struct {\n    Name  string `json:\"name\"`\n    Price float32 `json:\"price\"`\n}\n\n// [GET] url: /product/{id}\nfunc SomePostHandler(w http.ResponseWriter, r *http.Request) {\n    params := mux.Vars(r)\n    err := rest.CheckPathVariables(params, \"id\")\n    if err != nil {\n        // do stuff with error\n    }\n}\n```\n\nTODO List\n=========\n\n- [x] Working with custom errors\n- [ ] Add Response for ALB and API Gateway\n- [ ] Benchmarking (Memory, CPU)\n- [ ] Working with CheckPathVariables and GetPathVariable in Standard library\n- [ ] More tests\n- [ ] Working with pagination\n\nInstallation\n============\n\nTo install, use `go get` using go modules:\n\n```\ngo get github.com/edermanoel94/rest-go@latest\n```\n\nExample\n=======\n\nTo install and build:\n\n```\ncd examples\n```\n\nAnd use go modules for install packages:\n\n```\ngo mod tidy \n```\n\nThen, to run:\n\n```\ngo build\n```\n\nContributing\n============\n\nPlease feel free to submit issues, fork the repository and send pull requests!\n\n------\n\nLicense\n=======\n\nThis project is licensed under the terms of the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Federmanoel94%2Frest-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Federmanoel94%2Frest-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Federmanoel94%2Frest-go/lists"}