{"id":17988550,"url":"https://github.com/heyvito/raggett","last_synced_at":"2025-03-25T22:33:56.072Z","repository":{"id":42060473,"uuid":"436845256","full_name":"heyvito/raggett","owner":"heyvito","description":"🌏 Raggett is an opinionated Go HTTP Framework","archived":false,"fork":false,"pushed_at":"2024-05-24T13:10:56.000Z","size":97,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-19T10:10:56.106Z","etag":null,"topics":["framework","golang","http-server"],"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/heyvito.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":"SECURITY.md","support":null}},"created_at":"2021-12-10T04:05:01.000Z","updated_at":"2024-05-24T13:10:18.000Z","dependencies_parsed_at":"2022-08-12T03:40:54.051Z","dependency_job_id":null,"html_url":"https://github.com/heyvito/raggett","commit_stats":null,"previous_names":["heyvito/ragget"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyvito%2Fraggett","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyvito%2Fraggett/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyvito%2Fraggett/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heyvito%2Fraggett/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heyvito","download_url":"https://codeload.github.com/heyvito/raggett/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222099755,"owners_count":16931479,"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":["framework","golang","http-server"],"created_at":"2024-10-29T19:11:59.790Z","updated_at":"2024-10-29T19:11:59.909Z","avatar_url":"https://github.com/heyvito.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raggett\n[![codecov](https://codecov.io/gh/heyvito/raggett/branch/master/graph/badge.svg?token=BKKQ5K2FHG)](https://codecov.io/gh/heyvito/raggett)\n[![Test](https://github.com/heyvito/raggett/actions/workflows/go.yaml/badge.svg)](https://github.com/heyvito/raggett/actions/workflows/go.yaml)\n[![CodeQL](https://github.com/heyvito/raggett/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/heyvito/raggett/actions/workflows/codeql-analysis.yml)\n\n\u003e **Raggett** is an opinionated Go HTTP Server Framework\n\n## Installing\n\n```\ngo get github.com/heyvito/raggett@v0.1.7\n```\n\n## Usage\n\nRaggett is built on top of [Chi](https://github.com/go-chi/chi) to provide\nrouting and middlewares; the way it handles requests and responses are the\nmain difference between the common way Go HTTP servers are built. Instead of\nimplementing handlers dealing with both `http.Request` and\n`http.ResponseWriter`, the library encapsulates all common operations on a\nsingle `Request` object. The library also makes heavy usage of [Zap](https://github.com/uber-go/zap)\nto provide logging facilities.\n\nThe following snippet represents a simple Raggett Application:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"net/http\"\n\n    \"github.com/heyvito/raggett\"\n    \"go.uber.org/zap\"\n)\n\ntype HelloRequest struct {\n    *raggett.Request\n    Name string `form:\"name\" required:\"true\" blank:\"false\"`\n}\n\nfunc main() {\n    mux := raggett.NewMux(zap.L())\n\n    // Handlers must be a function accepting a single struct that uses\n    // *raggett.Request as a promoted field, and returns an error.\n    mux.Post(\"/\", func(r HelloRequest) error {\n        r.RespondString(fmt.Sprintf(\"Hello, %s!\", r.Name))\n        return nil\n    })\n\n    http.ListenAndServe(\":3000\", mux)\n}\n```\n\n\nThe same application can also be extended to provide both HTML and plain text\nresponses by implementing a structure implementing a set of interfaces provided\nby the library. For instance:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"net/http\"\n\n    \"github.com/heyvito/raggett\"\n    \"go.uber.org/zap\"\n)\n\ntype HelloRequest struct {\n    *raggett.Request\n    Name string `form:\"name\" required:\"true\" blank:\"false\"`\n}\n\ntype HelloResponse struct {\n    Name string\n}\n\nfunc (h HelloResponse) JSON() interface{} {\n    return map[string]interface{}{\n        \"greeting\": fmt.Sprintf(\"Hello, %s!\", h.Name),\n    }\n}\n\nfunc (h HelloResponse) HTML() string {\n    return fmt.Sprintf(\"\u003ch1\u003eHello, %s!\u003c/h1\u003e\", h.Name)\n}\n\nfunc main() {\n    mux := raggett.NewMux(zap.L())\n    mux.Post(\"/\", func(r HelloRequest) error {\n        r.Respond(HelloResponse{\n            Name: r.Name,\n        })\n        return nil\n    })\n\n    http.ListenAndServe(\":3000\", mux)\n}\n```\n\n## Accessing Form Values\n\nWhen defining a request object, form values can be automatically loaded and\nconverted to specific types by using tags:\n\n```go\ntype SignUpRequest struct {\n    *raggett.Request\n    Name                string `form:\"name\" required:\"true\" blank:\"false\"`\n    Email               string `form:\"email\" pattern:\"^.+@.+\\..+$\"`\n    SubscribeNewsletter bool   `form:\"subscribe\"`\n}\n```\n\n## Accessing QueryString Values\n\nThe same pattern used by forms can be applied to QueryString parameters:\n\n```go\ntype ListUsersRequest struct {\n    *raggett.Request\n    Page int `query:\"page\"`\n}\n```\n\n## Accessing URL Parameters\n\nAs Raggett is built on top of Chi, URL parameters can also be accessed through\nfields defined on structs and marked with tags:\n\n```go\ntype ListPostsForDay struct {\n    *raggett.Request\n    Day   int `url-param:\"day\"`\n    Month int `url-param:\"month\"`\n    Year  int `url-param:\"year\"`\n}\n\nmux.Get(\"/blog/posts/{day}/{month}/{year}\", func(r ListPostsForDay) error {\n        // ...\n    })\n```\n\n## Parsing Request Bodies\nWhen not using Forms or Multipart requests, applications can also rely on\nJSON or XML being posted, for instance. For that, Raggett has a set of Resolvers\nthat can be attached directly to a field indicating that the request's body\nmust be parsed and set it:\n\n```go\ntype SignUpRequest struct {\n    *raggett.Request\n    UserData struct {\n        Email string `json:\"email\"`\n        Name  string `json:\"name\"`\n    } `body:\"json\"`\n}\n```\n\n## Receiving Files\n\nMultipart data is also supported. To receive a single file:\n\n```go\ntype ExampleRequest struct {\n    *raggett.Request\n    Photo *raggett.FileHeader `form:\"photo\" required:\"false\"`\n}\n```\n\nOr multiple files:\n\n```go\ntype ExampleRequest struct {\n    *raggett.Request\n    Photos []*raggett.FileHeader `form:\"photo\" required:\"false\"`\n}\n```\n\n\u003e **ProTip™:** `raggett.FileHeader` is simply an alias to stdlib's\n`multipart.FileHeader`. Both types are interchangeable on Raggett.\n\n\n## Accessing Headers\nJust like other values, headers can also be obtained through tags:\n\n```go\ntype AuthenticatedRequest struct {\n    *raggett.Request\n    Authorization string `header:\"authorization\" required:\"true\"`\n}\n```\n\n## Defaults\n\nRaggett provides default handlers for errors such as validation (HTTP 400),\nruntime (HTTP 500), Not Found (HTTP 404), and Method Not Allowed (HTTP 405). For\nthose errors, the library is capable of responding to the following formats,\nbased on the `Accept` header provided by the client:\n\n- HTML\n- JSON\n- XML\n- Plain Text\n\nThe library also provides a \"Development\" mode, which augments information\nprovided by those error handlers:\n\n```go\nmux := raggett.NewMux(...)\nmux.Development = true\n```\n\n\u003e :warning: Warning! Setting Development to `true` on production environments is\nunadvised, since it may cause sensitive information to be exposed to the\ninternet.\n\n## License\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2021-2024 Vito Sartori\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheyvito%2Fraggett","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheyvito%2Fraggett","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheyvito%2Fraggett/lists"}