WebRequestManager - Comfortably submitting simple WebRequests

In some of my games, I use a Laravel-based API to load configurations and other data from a web server. For this purpose, I've developed a service that allows you to simply send text-based requests (usually JSON) to a server. The basis for this is, of course, Unity's built-in networking classes. The resulting service is made available via a manager: the WebRequestManager.

How to use the WebRequestManager

You can send simple WebRequests to a URL:


Of course, you can also use a verb other than GET:

WebRequestManager.service?.Send("https://myapi.com", WebRequestMethod.POST);

Then of course it makes sense to send your own data as well:

WebRequestManager.service?.Send("https://myapi.com", WebRequestMethod.POST, "my body");

And last but not least you can set your own headers:

var headers = new Dictionary<string, string>();
headers.Add("Content-Type", "application/json");
WebRequestManager.service?.Send("https://myapi.com", WebRequestMethod.POST, "my body", headers);

Process server responses

Since these are asynchronous processes, you must attach to the corresponding events to process the response. See the explanations for the PubSubManager.

The following should be noted for this module:

  • Events are published in the WebRequest channel.

  • The WebRequestSuccess event is published if the request was successful.

  • The WebRequestFailure event is sent if the request failed:

Your Feedback is important!

What do you think of the services presented here? Is there anything missing or does something not work as expected? As always, I'm happy to listen to your feedback. Let me know what you think about this module. You can use the comment section below the article for this. You can also find other ways to contact me here. If you found a bug or want an enhancement, please create an issue in the GitHub repository. Further documentation can be found in the README of the corresponding module.

There are no comments yet.