{"id":20533552,"url":"https://github.com/joeychilson/httputils","last_synced_at":"2025-03-06T03:13:53.949Z","repository":{"id":151693742,"uuid":"614825532","full_name":"joeychilson/httputils","owner":"joeychilson","description":"A library of helper functions for Go's net/http package.","archived":false,"fork":false,"pushed_at":"2023-03-16T12:00:25.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T13:19:36.150Z","etag":null,"topics":["go","golang","http","utils"],"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/joeychilson.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-16T11:58:33.000Z","updated_at":"2023-03-16T12:02:25.000Z","dependencies_parsed_at":"2023-06-04T04:30:25.332Z","dependency_job_id":null,"html_url":"https://github.com/joeychilson/httputils","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/joeychilson%2Fhttputils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Fhttputils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Fhttputils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Fhttputils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeychilson","download_url":"https://codeload.github.com/joeychilson/httputils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242138885,"owners_count":20078006,"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":["go","golang","http","utils"],"created_at":"2024-11-16T00:22:11.681Z","updated_at":"2025-03-06T03:13:53.923Z","avatar_url":"https://github.com/joeychilson.png","language":"Go","readme":"# httputils\n\nA library of helper functions for Go's `net/http` package.\n\n## Installation\n\n```bash\ngo get github.com/joeychilon/httputils\n```\n\n## Usage\n\n### Query Parameters\n\nThe library provides functions for parsing query parameters in HTTP requests:\n\n- `QueryString(r *http.Request, key string) string`: returns a string value for a query parameter.\n- `QueryStrings(r *http.Request, key string) []string`: returns a slice of strings for a query parameter.\n- `QueryInt(r *http.Request, key string) int`: returns an int value for a query parameter.\n- `QueryInts(r *http.Request, key string) []int`: returns a slice of ints for a query parameter.\n- `QueryBool(r *http.Request, key string) bool`: returns a bool value for a query parameter.\n\nHere's an example of how to use these functions:\n\n```go\nfunc myHandler(w http.ResponseWriter, r *http.Request) {\n    // Get a string query parameter\n    // key=foo =\u003e name = \"foo\"\n    name := httputils.QueryString(r, \"name\")\n\n    // Get a slice of strings query parameter\n    // key=foo,bar =\u003e names = [\"foo\", \"bar\"]\n    names := httputils.QueryStrings(r, \"names\")\n\n    // Get an int query parameter\n    // key=1 =\u003e id = 1\n    id := httputils.QueryInt(r, \"id\")\n\n    // Get a slice of ints query parameter\n    // key=1,2,3 =\u003e ids = [1, 2, 3]\n    ids := httputils.QueryInts(r, \"ids\")\n\n    // Get a bool query parameter\n    // key=true =\u003e enabled = true\n    enabled := httputils.QueryBool(r, \"enabled\")\n}\n```\n\n### JSON Responses\n\nThe library provides a function for writing JSON responses to the `http.ResponseWriter`:\n\n`WriteJSON(w http.ResponseWriter, statusCode int, data any)`: writes a JSON response with the given status code and data.\n\nHere's an example of how to use this function:\n\n```go\nfunc myHandler(w http.ResponseWriter, r *http.Request) {\n    // Get some data...\n    data := getSomeData()\n\n    // Write a JSON response\n    httputils.WriteJSON(w, http.StatusOK, data)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeychilson%2Fhttputils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeychilson%2Fhttputils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeychilson%2Fhttputils/lists"}