{"id":26859626,"url":"https://github.com/dubit/unity-http","last_synced_at":"2025-07-05T23:09:30.992Z","repository":{"id":41300831,"uuid":"135582930","full_name":"dubit/unity-http","owner":"dubit","description":"A handy wrapper for the Unity WebRequest system.","archived":false,"fork":false,"pushed_at":"2020-01-02T10:18:25.000Z","size":54,"stargazers_count":94,"open_issues_count":2,"forks_count":22,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-14T23:43:41.577Z","etag":null,"topics":["csharp","http","unity","webrequest"],"latest_commit_sha":null,"homepage":"","language":"C#","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/dubit.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":"2018-05-31T12:48:55.000Z","updated_at":"2025-06-08T22:18:07.000Z","dependencies_parsed_at":"2022-09-11T13:30:54.195Z","dependency_job_id":null,"html_url":"https://github.com/dubit/unity-http","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/dubit/unity-http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Funity-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Funity-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Funity-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Funity-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dubit","download_url":"https://codeload.github.com/dubit/unity-http/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Funity-http/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259957280,"owners_count":22937548,"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":["csharp","http","unity","webrequest"],"created_at":"2025-03-31T01:21:08.490Z","updated_at":"2025-07-05T23:09:30.974Z","avatar_url":"https://github.com/dubit.png","language":"C#","readme":"# unity-http\n\n## What is it?\nThe Http system has a quick and easy API for making http requests within Unity.  \nThe Http instance will run the WebRequest coroutines for you so you dont have to create it per request.   \n\n## Features\n* Singleton\n* Fluent API for configuration\n* Success, error and network error events\n* Super headers\n\n## Requirements\n* Unity 2018.3+\n* .NET 4.5\n* C# 7\n\n## Installation\n\nAdd it as a package using [Unity Package Manager](https://docs.unity3d.com/Manual/upm-git.html) or via submodule:  \n`git submodule add git@github.com:dubit/unity-http.git Assets/Duck/Http`\n\n## Releasing\n* Use [gitflow](https://nvie.com/posts/a-successful-git-branching-model/)\n* Create a release branch for the release\n* On that branch, bump version number in package json file, any other business (docs/readme updates)\n* Merge to master via pull request and tag the merge commit on master.\n* Merge back to development.#\n\n## How to use it.\nIf you are using an AssemblyDefinition then reference the Http Assembly.  \nImport the namespace `using DUCK.Http;`\n\n```c#\nvar request = Http.Get(\"http://mywebapi.com/\")\n\t.SetHeader(\"Authorization\", \"username:password\")\n\t.OnSuccess(response =\u003e Debug.Log(response.Text))\n\t.OnError(response =\u003e Debug.Log(response.StatusCode))\n\t.OnDownloadProgress(progress =\u003e Debug.Log(progress))\n\t.Send();\n```\n\n## API\n\n### Http Static Methods\n\nAll these methods return a new HttpRequest.  \n\n##### Get\n* `Http.Get(string uri)`  \n* `Http.GetTexture(string uri)`  \n##### Post\n* `Http.Post(string uri, string postData)`  \n* `Http.Post(string uri, WWWForm formData)`  \n* `Http.Post(string uri, Dictionary\u003cstring, string\u003e formData))`  \n* `Http.Post(string uri, List\u003cIMultipartFormSection\u003e multipartForm)`  \n* `Http.Post(string uri, byte[] bytes, string contentType)`  \n##### Post JSON\n* `Http.PostJson(string uri, string json)`  \n* `Http.PostJson\u003cT\u003e(string uri, T payload)` \n##### Put\n* `Http.Put(string uri, byte[] bodyData)` \n* `Http.Put(string uri, string bodyData)` \n##### Misc\n* `Http.Delete(string uri)`  \n* `Http.Head(string uri)`  \n\n### Http Request Configuration Methods\n\nAll these methods return the HttpRequest instance.  \n##### Headers\n* `SetHeader(string key, string value)`  \n* `SetHeaders(IEnumerable\u003cKeyValuePair\u003cstring, string\u003e\u003e headers)`  \n* `RemoveHeader(string key)`  \n* `RemoveSuperHeaders()`  \n##### Events\n* `OnSuccess(Action\u003cHttpResonse\u003e response)`  \n* `OnError(Action\u003cHttpResonse\u003e response)`  \n* `OnNetworkError(Action\u003cHttpResonse\u003e response)`  \n##### Progress\n* `OnUploadProgress(Action\u003cfloat\u003e progress)`  \n* `OnDownloadProgress(Action\u003cfloat\u003e progress)`  \n##### Configure\n* `SetRedirectLimit(int redirectLimit)`   \n* `SetTimeout(int duration)`\n\nRedirect limit subject to Unity's documentation.  \n* [Redirect Limit Documentation](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest-redirectLimit.html)\n\nProgress events will invoke each time the progress value has increased, they are subject to Unity's documentation.\n* [Upload Progress Documentation](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest-uploadProgress.html)\n* [Download Progress Documentation](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest-downloadProgress.html)\n \n### Http Request\n\n* `HttpRequest Send()`  \n* `void Abort()`  \n\n### Http Response\nThe callbacks for `OnSuccess`, `OnError` and `OnNetworkError` all return you a `HttpResponse`.  \nThis has the following properties:  \n##### Properties\n* `string Url`  \n* `bool IsSuccessful`  \n* `bool IsHttpError`  \n* `bool IsNetworkError`  \n* `long StatusCode`  \n* `ResponseType ResponseType`  \n* `byte[] Bytes`  \n* `string Text`  \n* `string Error`  \n* `Texture Texture`  \n* `Dictionary\u003cstring, string\u003e ResponseHeaders`  \n\n### Super Headers\n\nSuper Headers are a type of Header that you can set once to automatically attach to every Request you’re sending.  \nThey are Headers that apply to all requests without having to manually include them in each HttpRequest SetHeader call.\n\n* `Http.SetSuperHeader(string key, string value)`\n* `Http.RemoveSuperHeader(string key)` returns `bool`\n* `Http.GetSuperHeaders()` returns `Dictionary\u003cstring, string\u003e`\n\n\n## JSON Response Example\nIn this given example, the `response.Text` from `http://mywebapi.com/user.json` is:\n```json\n{\n    \"id\": 92,\n    \"username\": \"jason\"\n}\n```\n\nCreate a serializable class that maps the data from the json response to fields\n```c#\n[Serializable]\npublic class User\n{\n    [SerializeField]\n    public int id;\n    [SerializeField]\n    public string username;\n}\n```\n\nWe can listen for the event `OnSuccess` with our handler method `HandleSuccess`\n```c#\nvar request = Http.Get(\"http://mywebapi.com/user.json\")\n    .OnSuccess(HandleSuccess)\n    .OnError(response =\u003e Debug.Log(response.StatusCode))\n    .Send();\n```\n\nParse the `response.Text` to the serialized class `User` that we declared earlier by using Unity's built in [JSONUtility](https://docs.unity3d.com/ScriptReference/JsonUtility.html)\n```c#\nprivate void HandleSuccess(HttpResponse response)\n{\n     var user = JsonUtility.FromJson\u003cUser\u003e(response.Text);\n     Debug.Log(user.username);\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdubit%2Funity-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdubit%2Funity-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdubit%2Funity-http/lists"}