{"id":24083281,"url":"https://github.com/mitranim/rd","last_synced_at":"2026-03-03T13:41:07.980Z","repository":{"id":46212247,"uuid":"282907301","full_name":"mitranim/rd","owner":"mitranim","description":"Tool for decoding HTTP requests into Go structs. Transparently supports multiple formats: JSON, URL-encoded, multipart. ","archived":false,"fork":false,"pushed_at":"2024-08-15T14:00:22.000Z","size":72,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-03T05:05:43.171Z","etag":null,"topics":["form","golang","http","json","multipart","request"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/mitranim/rd","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitranim.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-27T13:32:09.000Z","updated_at":"2024-08-15T14:00:26.000Z","dependencies_parsed_at":"2024-06-21T00:07:39.515Z","dependency_job_id":"4e26ef79-cd8d-459c-b9b1-1842fd39affc","html_url":"https://github.com/mitranim/rd","commit_stats":null,"previous_names":["mitranim/reqdec"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Frd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Frd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Frd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Frd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitranim","download_url":"https://codeload.github.com/mitranim/rd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233275539,"owners_count":18651573,"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":["form","golang","http","json","multipart","request"],"created_at":"2025-01-09T23:56:17.165Z","updated_at":"2025-09-16T15:31:51.253Z","avatar_url":"https://github.com/mitranim.png","language":"Go","readme":"## Overview\n\nShort for **R**equest **D**ecoding. Missing feature of the Go standard library: decoding arbitrary HTTP requests into structs. Features:\n\n* Transparent support for different content types / encoding formats:\n  * URL query.\n  * URL-encoded form.\n  * Multipart form.\n  * JSON.\n* Transparent support for different HTTP methods:\n  * Read-only -\u003e parse only URL query.\n  * Non-read-only -\u003e parse only request body.\n* Transparent support for various text-parsing interfaces.\n* Support for membership testing (was X present in request?), useful for PATCH semantics.\n* Tiny and dependency-free.\n\nAPI docs: https://pkg.go.dev/github.com/mitranim/rd.\n\n## Example\n\n1-call decoding. Works for any content type.\n\n```golang\nimport \"github.com/mitranim/rd\"\nimport \"github.com/mitranim/try\"\n\nvar input struct {\n  FieldOne string `json:\"field_one\"`\n  FieldTwo int64  `json:\"field_two\"`\n}\ntry.To(rd.Decode(req, \u0026input))\n```\n\nDownload once, decode many times. Works for any content type.\n\n```golang\nimport \"github.com/mitranim/rd\"\nimport \"github.com/mitranim/try\"\n\ndec := rd.TryDownload(req)\n\nvar input0 struct {\n  FieldOne string `json:\"field_one\"`\n}\ntry.To(dec.Decode(\u0026input0))\n\nvar input1 struct {\n  FieldTwo int64  `json:\"field_two\"`\n}\ntry.To(dec.Decode(\u0026input1))\n\n// Membership testing.\nhaser := dec.Haser()\nfmt.Println(haser.Has(`fieldTwo`))\n```\n\n## Changelog\n\n### v0.3.0\n\n`Decode` and `Download` now use the URL query when the request has no body and no content type. This library no longer checks the HTTP method of the request. Read-only methods and non-read-only methods are treated the same.\n\nRemoved `Form.Download`, `TypeJsonUtf8`, `TypeFormUtf8`, `TypeMultiUtf8`.\n\n### v0.2.3\n\nInternal change: renamed `Error.Append` to `Error.AppendTo` for consistency with other libraries.\n\nMinor change: added `Type`, `TypeJsonUtf8`, `TypeFormUtf8`, `TypeMultiUtf8`.\n\n### v0.2.2\n\nDecoders now implement a new interface `Setter` that creates a `Set` of known keys.\n\n### v0.2.1\n\nFixed edge case bug where `Form.Decode` wouldn't invoke `SliceParser` for non-slices.\n\n### v0.2.0\n\nBreaking revision:\n\n* Much more flexible.\n* Much faster.\n* Much more test coverage.\n* Renamed from `reqdec` to `rd` for brevity.\n* Dependency-free.\n\n### v0.1.7\n\nBreaking: when decoding from JSON, `{\"\u003cfield\u003e\": null}` zeroes the matching destination field, instead of being ignored. This is an intentional deviation. The `json` package makes no distinction between a missing field and a field whose value is `null`. However, in order to support `PATCH` semantics, we often want to decode into _non-zero_ output structs, updating fields that are present in the input, while ignoring fields missing from the input. Using `null` to zero the output is essential for this use case. If `null` was ignored, clients would be unable to set empty values, able only to set new non-empty values.\n\nBreaking: when decoding from formdata, `\"\"` is treated as a \"null\" or \"zero value\" for output fields that are not slices and don't implement `SliceParser`. This is extremely useful for standard DOM forms.\n\nRemoved `Reqdec.DecodeAt`. It wasn't compatible with the new logic for struct field decoding, and supporting it separately would require code duplication.\n\nRenamed `FromQuery` → `FromVals`.\n\nAdded `FromJson`.\n\n### v0.1.6\n\nAdded `FromQuery` and `FromReqQuery`.\n\n### v0.1.5\n\nAdded `SliceParser` for parsing non-slices from lists.\n\n### v0.1.4\n\nChanged the license to Unlicense.\n\n### v0.1.3\n\nWhen decoding into a struct where some of the fields are embedded struct pointers, those nested structs are allocated only if some of their fields are present in the request.\n\nAlso moved some reflection-related utils to a [tiny dependency](https://github.com/mitranim/refut).\n\n### v0.1.2\n\nFirst tagged release.\n\n## License\n\nhttps://unlicense.org\n\n## Misc\n\nI'm receptive to suggestions. If this library _almost_ satisfies you but needs changes, open an issue or chat me up. Contacts: https://mitranim.com/#contacts\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitranim%2Frd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitranim%2Frd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitranim%2Frd/lists"}