Blest 0.1.0
dotnet add package Blest --version 0.1.0
NuGet\Install-Package Blest -Version 0.1.0
<PackageReference Include="Blest" Version="0.1.0" />
paket add Blest --version 0.1.0
#r "nuget: Blest, 0.1.0"
// Install Blest as a Cake Addin #addin nuget:?package=Blest&version=0.1.0 // Install Blest as a Cake Tool #tool nuget:?package=Blest&version=0.1.0
BLEST .NET
The .NET reference implementation of BLEST (Batch-able, Lightweight, Encrypted State Transfer), an improved communication protocol for web APIs which leverages JSON, supports request batching and selective returns, and provides a modern alternative to REST.
To learn more about BLEST, please visit the website: https://blest.jhunt.dev
For a front-end implementation in React, please visit https://github.com/jhuntdev/blest-react
Features
- Built on JSON - Reduce parsing time and overhead
- Request Batching - Save bandwidth and reduce load times
- Compact Payloads - Save more bandwidth
- Selective Returns - Save even more bandwidth
- Single Endpoint - Reduce complexity and improve data privacy
- Fully Encrypted - Improve data privacy
Installation
Install BLEST .NET from NuGet
dotnet add package Blest
Usage
This core class of this library has an interface similar to ASP.NET Core. It also provides a Router
class with a Handle
method for use in an existing .NET API and an HttpClient
class with a Request
method for making BLEST HTTP requests.
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Blest;
// Instantiate your app
var app = new Blest({ "timeout": 1000, "cors": true });
// Create some middleware (optional)
app.Use(async (parameters, context) =>
{
if (parameters.ContainsKey("name"))
{
context["user"] = new Dictionary<string, object?>
{
{ "name", parameters["name"] }
};
}
else
{
throw new Exception("Unauthorized");
}
});
// Create a route controller
app.Map('greet', async (parameters, context) =>
{
if (!context.ContainsKey("user") || context["user"] == null || !((Dictionary<string, object?>)context["user"]).ContainsKey("name"))
{
throw new Exception("Unauthorized");
}
return new Dictionary<string, object?>
{
{ "greeting", "Hi, " + ((Dictionary<string, object?>)context["user"])["name"] + "!" }
};
});
// Start your BLEST server
app.Run();
Router
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Blest;
// Instantiate your Router
var router = new Router({ "timeout": 1000 });
// Create some middleware (optional)
router.Use(async (parameters, context) =>
{
if (parameters.ContainsKey("name"))
{
context["user"] = new Dictionary<string, object?>
{
{ "name", parameters["name"] }
};
}
else
{
throw new Exception("Unauthorized");
}
});
// Create a route controller
router.Map('greet', async (parameters, context) =>
{
if (!context.ContainsKey("user") || context["user"] == null || !((Dictionary<string, object?>)context["user"]).ContainsKey("name"))
{
throw new Exception("Unauthorized");
}
return new Dictionary<string, object?>
{
{ "greeting", "Hi, " + ((Dictionary<string, object?>)context["user"])["name"] + "!" }
};
});
// ...later in your application
// Handle a request
result, error = router.Handle(jsonData, context);
if (error is not null)
{
// do something in case of error
}
else
{
// do something with the result
}
HttpClient
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Blest;
class Program
{
static async Task Main()
{
// Create a client
Dictionary<string, object?> options = new Dictionary<string, object?>
{
["headers"] = new Dictionary<string, object?>
{
["Authorization"] = "Bearer token"
}
};
var client = new HttpClient("http://localhost:8080", options);
try
{
// Send a request
IDictionary<string, object?> parameters = new Dictionary<string, object?> {
{ "name", "Steve" }
};
var selector = new object[] { "greeting" };
var result = await client.Request("greet", parameters, selector);
// Do something with the result
}
catch (Exception error)
{
// Do something in case of error
}
}
}
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.