Simple HTTP client for Unity

I just released SimpleHTTP, a very easy-to-use HTTP client for Unity, and I’d like to get some feedback from you.

The main reason why I did it (and made it free) is because I think that HTTP is something fundamental for games nowadays, and I couldn’t find a free and simple-enough solution to perform a GET or a POST. So, to give you a brief example, a POST call with SimpleHTTP would look like this:

IEnumerator Post() {
    // Let's say that this the object you want to create
    Post post = new Post ("Test", "This is a test", 1);

    // Create the request object and use the helper function `RequestBody` to create a body from JSON
    Request request = new Request ("https://jsonplaceholder.typicode.com/posts");
        .Post (RequestBody.From<Post> (post));

    // Instantiate the client
    Client http = new Client ();
    // Send the request
    yield return http.Send (request);

    // Use the response if the request was successful, otherwise print an error
    if (http.IsSuccessful ()) {
        Response resp = http.Response ();
        Debug.Log("status: " + resp.Status().ToString() + "\nbody: " + resp.Body());
    } else {
        Debug.Log("error: " + http.Error());
    }
}

You can check the list of current features in the github page. One of my main goals was to create a consistent and legible API, and abstract all the complex logic of upload/download handlers, byte arrays, etc. It works asynchronously, without callbacks or promises.

I submitted it to the Asset Store but it is still in review and I’m still working on a full reference documentation but I’d love to hear what you think about it so far.

Is it something you consider useful? Is it something you would use in any future project?

1 Like

Sorry for my incredibly stupid question, but what are the uses for HTTP clients in games?

thank you :slight_smile:

It’s not stupid at all, so nothing to excuse :slight_smile: You can use HTTP for any RESTful backend, for example, Amazon Lambda, Firebase Functions or anything providing REST APIs. Let’s say you want to post a highscore to a score tracking application or you have a REST service that tracks achievements and leaderboards and provides a REST API, then you need an HTTP client for that.

Right now I’m working on a simple backend for a game using Firebase Functions (REST API) + Firebase Database, so I’m needing an HTTP client to send requests and fetch information from it.

I hope this clarifies your doubt.