Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.3.0 #18

Merged
merged 37 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d31c6b9
Update MainScript.cs
jdnichollsc Mar 5, 2018
7e4e680
Update MainScript.cs
jdnichollsc Mar 5, 2018
98201e0
Update README.md
jdnichollsc Mar 5, 2018
1f313cf
Add documentation to publish to the Unity Store
jdnichollsc Mar 5, 2018
7e81209
Merge branch 'master' of https://github.com/proyecto26/RestClient
jdnichollsc Mar 5, 2018
2088f5e
Update README.md
jdnichollsc Mar 5, 2018
a9cffff
Update README.md
jdnichollsc Mar 5, 2018
76ba20b
Update README.md
jdnichollsc Mar 5, 2018
f8bf34b
Update README.md
jdnichollsc Mar 10, 2018
7c6ec99
Fix issue building demo
jdnichollsc Mar 10, 2018
bfb07e4
Update README.md
jdnichollsc Mar 12, 2018
80b1907
Update README.md
jdnichollsc Mar 12, 2018
26f18ba
Update MainScript.cs
jdnichollsc Mar 12, 2018
b0d07aa
Update README.md
jdnichollsc Mar 12, 2018
7c334b7
Update README.md
jdnichollsc Mar 13, 2018
9ae2d07
Update README.md
jdnichollsc Mar 14, 2018
824699d
Update StaticCoroutine.cs
Nepoxx Apr 11, 2018
bbbbeaf
Merge pull request #16 from Nepoxx/patch-1
jdnichollsc May 15, 2018
e287f94
Fix exception with status code and add default request for other HTTP…
jdnichollsc May 15, 2018
d848f73
Improve documentation and Use the overloading mechanism instead of th…
jdnichollsc May 15, 2018
fefeda2
Create .codacy.yml
jdnichollsc May 16, 2018
e6d66f8
Fix the demo with the last changes
jdnichollsc May 19, 2018
30ee750
Fix requests to include BodyString property to serialize the JSON wit…
jdnichollsc May 19, 2018
c097139
Update the README with the last changes
jdnichollsc May 19, 2018
ba3339a
Update README
jdnichollsc May 19, 2018
3511b1f
Fix demo of the generic request
jdnichollsc May 19, 2018
899700b
Fix references to use RequestException
jdnichollsc May 20, 2018
a01de4d
Remove redundant 'base()' call.
jdnichollsc May 20, 2018
a0f1b42
Add FormSections and SimpleForm to the RequestHelper to support multi…
jdnichollsc May 20, 2018
590fbed
Add method to abort the request
jdnichollsc May 20, 2018
0daade9
Fix content type for application/x-www-form-urlencoded
jdnichollsc May 21, 2018
2d546a1
Fix README to include all new properties of the RequestHelper class
jdnichollsc May 21, 2018
fff8aca
Add format to the examples of the README
jdnichollsc May 21, 2018
270f152
Update official documentation to publish to the Unity store
jdnichollsc May 22, 2018
6e59ad5
Improve the documentation and the demo before publish the release 1.3.0
jdnichollsc May 22, 2018
0f5ee85
Update nuspec with the 1.3.0 version
jdnichollsc May 22, 2018
eb8ae12
Publish version 1.3.0
jdnichollsc May 22, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exclude_paths:
- '.demo/**'
136 changes: 103 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.org/proyecto26/RestClient.svg?branch=master)](https://travis-ci.org/proyecto26/RestClient)

# RestClient for Unity 🤘
> Supported Unity versions 2017.2 or higher

<img src="img/icono.png" width="150px" align="right" alt="Proyecto26.RestClient logo" />

Expand Down Expand Up @@ -33,6 +34,18 @@ RestClient.GetArray<Post>(api + "/posts").Then(response => {
}).Catch(err => EditorUtility.DisplayDialog ("Error", err.Message, "Ok"));
```

## Supported platforms
The [UnityWebRequest](https://docs.unity3d.com/Manual/UnityWebRequest.html) system supports most Unity platforms:

* All versions of the Editor and Standalone players
* WebGL
* Mobile platforms: iOS, Android
* Universal Windows Platform
* PS4 and PSVita
* XboxOne
* HoloLens
* Nintendo Switch

## Demo ⏯
Do you want to see this beautiful package in action? Download the demo [here](https://minhaskamal.github.io/DownGit/#/home?url=https://github.com/proyecto26/RestClient/tree/master/demo)

Expand All @@ -58,27 +71,47 @@ Other option is download this package from **NuGet** with **Visual Studio** or u
The package to search for is **[Proyecto26.RestClient](https://www.nuget.org/packages/Proyecto26.RestClient/)**.

## Getting Started 📚
The default methods **(GET, POST, PUT, DELETE)** are:
```
The default methods **(GET, POST, PUT, DELETE, HEAD)** are:
```csharp
RestClient.Get("https://jsonplaceholder.typicode.com/posts/1").Then(response => {
EditorUtility.DisplayDialog("Response", response.text, "Ok");
})

EditorUtility.DisplayDialog("Response", response.Text, "Ok");
});
RestClient.Post("https://jsonplaceholder.typicode.com/posts", newPost).Then(response => {
EditorUtility.DisplayDialog("Status", response.statusCode.ToString(), "Ok");
})

EditorUtility.DisplayDialog("Status", response.StatusCode.ToString(), "Ok");
});
RestClient.Put("https://jsonplaceholder.typicode.com/posts/1", updatedPost).Then(response => {
EditorUtility.DisplayDialog("Status", response.statusCode.ToString(), "Ok");
})

EditorUtility.DisplayDialog("Status", response.StatusCode.ToString(), "Ok");
});
RestClient.Delete("https://jsonplaceholder.typicode.com/posts/1").Then(response => {
EditorUtility.DisplayDialog("Status", response.statusCode.ToString(), "Ok");
EditorUtility.DisplayDialog("Status", response.StatusCode.ToString(), "Ok");
});
RestClient.Head("https://jsonplaceholder.typicode.com/posts").Then(response => {
EditorUtility.DisplayDialog("Status", response.StatusCode.ToString(), "Ok");
})
```

But we are going to create a class **"User"** and the HTTP requests to load **JSON** data easily:
And we have a generic method to create any type of request:
```csharp
RestClient.Request(new RequestHelper {
Uri = "https://jsonplaceholder.typicode.com/photos",
Method = "POST",
Timeout = 10000,
Headers = new Dictionary<string, string> {
{ "Authorization", "Bearer JWT_token..." }
},
Body = newPost, //Content-Type: application/json
BodyString = "Use it instead of 'Body' if you want to use other tool to serialize the JSON",
SimpleForm = new Dictionary<string, string> {}, //Content-Type: application/x-www-form-urlencoded
FormSections = new List<IMultipartFormSection>() {}, //Content-Type: multipart/form-data
ChunkedTransfer = true,
IgnoreHttpException = true, //Prevent to catch http exceptions
}).Then(response => {
EditorUtility.DisplayDialog("Status", response.StatusCode.ToString(), "Ok");
});
```

With all the methods we have the possibility to indicate the type of response, in the following example we're going to create a class and the **HTTP** requests to load **JSON** data easily:
```csharp
[Serializable]
public class User
{
Expand All @@ -92,70 +125,107 @@ public class User
```

* **GET JSON**
```
```csharp
var usersRoute = "https://jsonplaceholder.typicode.com/users";
RestClient.Get<User>(usersRoute + "/1").Then(firstUser => {
EditorUtility.DisplayDialog("JSON", JsonUtility.ToJson(firstUser, true), "Ok");
})
```
* **GET Array**
});
```
* **GET Array (JsonHelper is an extension to manage arrays)**
```csharp
RestClient.GetArray<User>(usersRoute).Then(allUsers => {
EditorUtility.DisplayDialog("JSON Array", JsonHelper.ArrayToJsonString<User>(allUsers, true), "Ok");
})
});
```

Also we can create different classes for custom responses:
```
```csharp
[Serializable]
public class CustomResponse
{
public int id;
}
```
* **POST**
```
```csharp
RestClient.Post<CustomResponse>(usersRoute, newUser).Then(customResponse => {
EditorUtility.DisplayDialog("JSON", JsonUtility.ToJson(customResponse, true), "Ok");
})
});
```
* **PUT**
```
```csharp
RestClient.Put<CustomResponse>(usersRoute + "/1", updatedUser).Then(customResponse => {
EditorUtility.DisplayDialog("JSON", JsonUtility.ToJson(customResponse, true), "Ok");
})
});
```

## Custom HTTP Headers and Options 💥
**HTTP Headers**, such as `Authorization`, can be set in the **DefaultRequestHeaders** object for all requests
```
```csharp
RestClient.DefaultRequestHeaders["Authorization"] = "Bearer ...";
```

Also we can add specific options and override default headers for a request
```
var requestOptions = new RequestHelper {
url = "https://jsonplaceholder.typicode.com/photos",
headers = new Dictionary<string, string>{
```csharp
var currentRequest = new RequestHelper {
Uri = "https://jsonplaceholder.typicode.com/photos",
Headers = new Dictionary<string, string> {
{ "Authorization", "Other token..." }
}
};
RestClient.GetArray<Photo>(requestOptions).Then(response => {
EditorUtility.DisplayDialog("Header", requestOptions.GetHeader("Authorization"), "Ok");
})
RestClient.GetArray<Photo>(currentRequest).Then(response => {
EditorUtility.DisplayDialog("Header", currentRequest.GetHeader("Authorization"), "Ok");
});

currentRequest.UploadProgress; //To know the progress by uploading data to the server
currentRequest.DownloadProgress; //To know the progress by downloading data from the server
currentRequest.Abort(); //Abort the request manually
```

And later we can clean the default headers for all requests
```
```csharp
RestClient.CleanDefaultHeaders();
```

### Example
- Unity
```csharp
[Serializable]
public class ServerResponse {
public string id;
public string date; //DateTime is not supported by JsonUtility
}
[Serializable]
public class User {
public string firstName;
public string lastName;
}
RestClient.Post<ServerResponse>("www.api.com/endpoint", new User {
firstName = "Juan David",
lastName = "Nicholls Cardona"
}).Then(response => {
EditorUtility.DisplayDialog("ID: ", response.id, "Ok");
EditorUtility.DisplayDialog("Date: ", response.date, "Ok");
});
```
- NodeJS as Backend (Using [Express](http://expressjs.com/es/starter/hello-world.html))
```js
router.post('/', function(req, res) {
console.log(req.body.firstName)
res.json({
id: 123,
date: new Date()
})
});
```

## Collaborators 🥇
[<img alt="jdnichollsc" src="https://avatars3.githubusercontent.com/u/3436237?v=3&s=117" width="117">](https://github.com/diegoossa) | [<img alt="jdnichollsc" src="https://avatars3.githubusercontent.com/u/2154886?v=3&s=117" width="117">](https://github.com/jdnichollsc) |
:---: | :---: |
[Diego Ossa](mailto:diegoossa@gmail.com) | [Juan Nicholls](mailto:jdnichollsc@hotmail.com) |

## Credits 👍
* [Real Serious Games/C-Sharp-Promise](https://github.com/Real-Serious-Games/C-Sharp-Promise)
* **Promises library for C#:** [Real Serious Games/C-Sharp-Promise](https://github.com/Real-Serious-Games/C-Sharp-Promise)

## Supporting 🍻
I believe in Unicorns 🦄
Expand Down
2 changes: 0 additions & 2 deletions demo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
Expand Down