All Projects → satanas → unity-simple-http

satanas / unity-simple-http

Licence: other
A dead simple HTTP client for Unity3D

Programming Languages

C#
18002 projects
python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to unity-simple-http

Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (+2009.38%)
Mutual labels:  http-client, rest-client
Restclient Cpp
C++ client for making HTTP/REST requests
Stars: ✭ 1,206 (+3668.75%)
Mutual labels:  http-client, rest-client
Hoodie
Hoodie is a type safe wrapper around jersey http client
Stars: ✭ 22 (-31.25%)
Mutual labels:  http-client, rest-client
Restc Cpp
Modern C++ REST Client library
Stars: ✭ 371 (+1059.38%)
Mutual labels:  http-client, rest-client
Crest
HTTP and REST client for Crystal
Stars: ✭ 174 (+443.75%)
Mutual labels:  http-client, rest-client
Vial Http
Simple http rest tool for vim
Stars: ✭ 412 (+1187.5%)
Mutual labels:  http-client, rest-client
Fluentlyhttpclient
Http Client for .NET Standard with fluent APIs which are intuitive, easy to use and also highly extensible.
Stars: ✭ 73 (+128.13%)
Mutual labels:  http-client, rest-client
Taviloglu.Wrike.ApiClient
.NET Client for Wrike API
Stars: ✭ 24 (-25%)
Mutual labels:  http-client, rest-client
Python Simple Rest Client
Simple REST client for python 3.6+
Stars: ✭ 143 (+346.88%)
Mutual labels:  http-client, rest-client
Frequest
FRequest - A fast, lightweight and opensource desktop application to make HTTP(s) requests
Stars: ✭ 130 (+306.25%)
Mutual labels:  http-client, rest-client
Requester
Powerful, modern HTTP/REST client built on top of the Requests library
Stars: ✭ 273 (+753.13%)
Mutual labels:  http-client, rest-client
Rester
A REST client for almost any web service (Firefox and Chrome Extension)
Stars: ✭ 192 (+500%)
Mutual labels:  http-client, rest-client
Vscode Restclient
REST Client Extension for Visual Studio Code
Stars: ✭ 3,289 (+10178.13%)
Mutual labels:  http-client, rest-client
Resty
Simple HTTP and REST client library for Go
Stars: ✭ 5,368 (+16675%)
Mutual labels:  http-client, rest-client
roast.vim
An HTTP client for Vim, that can also be used as a REST client.
Stars: ✭ 78 (+143.75%)
Mutual labels:  http-client, rest-client
Rest Client
A tool for automated testing REST API, generating exquisite testing report and REST API documentation.
Stars: ✭ 1,181 (+3590.63%)
Mutual labels:  http-client, rest-client
csharp-http-client
Twilio SendGrid's C# HTTP Client for calling APIs
Stars: ✭ 25 (-21.87%)
Mutual labels:  http-client, rest-client
RESTEasy
REST API calls made easier
Stars: ✭ 12 (-62.5%)
Mutual labels:  http-client, rest-client
Fetcher Ts
Type-safe wrapper around Fetch API
Stars: ✭ 87 (+171.88%)
Mutual labels:  http-client, rest-client
Fshttp
A lightweight F# HTTP library.
Stars: ✭ 181 (+465.63%)
Mutual labels:  http-client, rest-client

SimpleHTTP

SimpleHTTP is a dead simple HTTP client for Unity, because HTTP shouldn't be that hard.

Installation

Download the .unitypackage file and inside Unity go to the menu Assets -> Import New Assets... and select the package for SimpleHTTP.

Features

Currently, SimpleHTTP supports:

  • HTTP and HTTPS
  • GET, POST, PUT and DELETE
  • Headers
  • Timeouts

All of these features with a simple and consistent API. In the future it will also support:

  • More validations
  • URL parsing
  • Delegates to indicate progress

Usage

SimpleHTTP is very, very, very, simple to use (really!) and it is asynchronous. You can send any type of request basically with three objects: Request, Client and Response. Consider that the general flow would be something like this:

  • Create a request
  • Use the client to send the request
  • Get the response
  • Profit!

To make your life even easier, SimpleHTTP support JSON serialization and deserialization, so you don't need to worry about that. To use it in your Unity scripts, you just need to add the following instruction at the top of your .cs scripts:

using SimpleHTTP;

Below are some examples that can help you understand how it works. Also you can refer to the Examples folder for a full working example of the library with a demo scene.

GET

IEnumerator Get() {
    // Create the request object
    Request request = new Request ("https://jsonplaceholder.typicode.com/posts/1");

    // 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());
    }
}

POST with JSON payload (raw)

As I mentioned before, SimpleHTTP supports JSON serialization and deserialization, so you just need to have serializable POJOs in your code. Let's say you want to fetch a post from a certain URL and your POJO looks like this:

[System.Serializable]
public class Post {
    private string title;
    private string body;
    private int userId;

    public Post(string title, string body, int userId) {
        this.title = title;
        this.body = body;
        this.userId = userId;
    }
}

Then you can send a POST to the server to create a new post.

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());
    }
}

Consider that the Post object can be something more complex, with other objects inside (check the UserProfile.cs class in the examples folder for more details). Also, SimpleHTTP will set the content type of this request automagically as "application/json", so another thing you don't need to worry about :).

POST with FormData

If the server only supports x-www-form-urlencoded you still can use SimpleHTTP to send your request. In this case, you just need to use the FormData helper to create the body of your request. Then you can send the POST as you would normally do (and SimpleHTTP will also take care of the content type for this request).

Byte[] myFile = File.ReadAllBytes("file/path/test.jpg");

IEnumerator Post() {
    FormData formData = new FormData ()
        .AddField ("userId", "1")
        .AddField ("body", "Hey, another test")
        .AddField ("title", "Did I say test?")
        .AddFile("file", myFile, "test.jpg", "image/jpg");

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

    // 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());
    }
}

Adding headers to your request

So, you also need to add certain headers to your request? Do not fear! SimpleHTTP also let you do that easily. Just use the AddHeader method in your request and you're all set.

IEnumerator Get() {
    // Create the request object
    Request request = new Request ("https://jsonplaceholder.typicode.com/posts/1")
        .AddHeader ("Test-Header", "test")
        .AddHeader ("X-Fancy-Id", "some-fancy-id");

    // 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());
    }
}

PUT and DELETE

PUT requests will work exactly the same than POSTs, you just need to use Put() instead. And DELETEs will work similarly to GETs, just use Delete() for that and you're done.

License

SimpleHTTP is licensed under the Apache License, Version 2.0.

Donation

SimpleHTTP is free and open source because I think that HTTP is something fundamental and basic for games nowadays, and there are no simple and free solutions to perform basic tasks like GET or POST. However, I'm open to donations, and if you really love SimpleHTTP I'd really appreciate if you buy me a coffee to continue improving this small and simple client for the use of all of us.

https://paypal.me/satanas82

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].