Scriptable Web Request is a Unity tool that simplifies the process of making HTTP requests (GET, POST, PUT, DELETE, etc.) using ScriptableObjects. This allows you to handle web requests in a modular and reusable way, making your code cleaner and easier to maintain.
- Modular HTTP request handling with ScriptableObjects.
- Support for GET, POST, PUT, and DELETE methods.
- Easy integration with Unity projects.
- Customizable headers and content type.
- Asynchronous request handling.
- Debugging support to monitor requests and responses.
- Support Cancellation Token for cancelling the on-progress request.
Because unity doesn't support custom dependency for package outside Unity Registry, you need to install Unity-Web-Request library from Jeffrey Lanters.
You could install both of the packages by add the following line to the dependencies section of your project's manifest.json file
"nl.jeffreylanters.web-requests": "git+https://github.com/jeffreylanters/unity-web-requests"
"com.nabilahkishou.scriptable-web-request": "https://github.com/NabilahKishou/Scriptable-Web-Request.git"- Create a new ScriptableObject by right-clicking in the Project window and navigating to Create > Web Request > Basic.
- Configure the request by setting the following properties:
- Endpoint: The endpoint you want to call.
- HTTP Method: Choose between GET, POST, PATCH, PUT, or DELETE.
- Content Type: Define the data type you want to send, mostly using Application JSON.
- Need Auth: If the request needed an auth you can check this.
Use the ScriptableWebRequest object in your scripts to send requests. For example:
BasicRequest _pingRequest; // request for ping to server
async Task<bool> Ping()
{
WebRequestResponse response = null;
try {
response = await ping.SendRequest(); // sending the request
}
catch (WebRequestException e) {
return false;
}
return response.Text().Contains("pong");
}This project is licensed under the MIT License. See the LICENSE file for details.
For questions or support, please open an issue in the repository or contact NabilahKishou.
This library could exist solely because the library from Jeffrey Lanters, kindly checkout his repository yourself.