-
Notifications
You must be signed in to change notification settings - Fork 2
Restful Resources
Chromely resources are accessed using using Restful URLs.
Both app types use Ajax HTTP/XHR requests, .NET/Javascript integrated bound objects (JSObjects) and Generic Message Routing object (cefQuery) are based on same Restful framework and can access same resources.
Chromely Restful representations are these formats
- HTTP/XHR - scheme://domain/controller/action
- JSObjects - /controller/action
- cefQuery - /controller/action
- All responses are assumed (Json). But this can be changed in custom handlers and JSObjects.
For Ajax, JSObject and cefQuery requests, the route path - /controller/action - must be registered and mapped to a Route. Each Route has a mapping of the required resource.
To achieve this, the developer must:
- Implement a "Controller" class. The class must inherit the abstract class - ChromelyController implemented. This can include current executing assembly.
- Register custom scheme handlers that have the required schemes and domains or JSObjects.
- Implement the HTTP/XHR, the JSObjects or CefQuery in the [UI - HTTP/XHR][UI - JSObjects][UI - CefQuery].
- Register all assemblies where ChromelyController classes are
A typical ChromelyController implementation will be like: **** Remember the ControllerProperty so the assembly scanner can discover it.
In Program.cs, register custom schemes:
var config = ChromelyConfiguration()
.Create()
....
.UseDefaultHttpSchemeHandler("http", "chromely.com")
.....
Or
var config = ChromelyConfiguration()
.Create()
....
.RegisterSchemeHandler("http", "chromely.com", new CefSharpHttpSchemeHandlerFactory())
.RegisterSchemeHandler("http", "chromely2.com", new CustomSchemeHandlerFactory())
.....
In Controller:
[ControllerProperty(Name = "DemoController", Route = "democontroller")]
public class DemoController : ChromelyController
{
public DemoController()
{
RegisterGetRequest("/democontroller/movies", GetMovies);
RegisterPostRequest("/democontroller/savemovies", SaveMovies);
}
}
Where:
Paths: /democontroller/movies (GET)
/democontroller/savemovies (POST)
Resources: GetMovies
SaveMovies
A sample HTTP/XHR GET request in the UI will be:
var http = new XMLHttpRequest();
var url = "http://chromely.com/democontroller/movies";
http.open("GET", url, true);
http.onreadystatechange = function () {
if (http.readyState == 4 && http.status == 200) {
var jsonData = JSON.parse(http.responseText);
...... process response
}
}
http.send();
A sample JSObjects GET request in the UI will be:
function callbackBoundObjectResult(res) {
var jsonData = JSON.parse(res.ResponseText);
if (jsonData.ReadyState == 4 && jsonData.Status == 200) {
.... process response
}
}
function boundObjectRun() {
boundControllerAsync.getJson("/democontroller/movies", null, callbackBoundObjectResult);
}
Where:
Callback function: callbackBoundObjectResult
A sample cefQuery GET request in the UI will be:
function messageRouterResult(response) {
var jsonData = JSON.parse(response);
if (jsonData.ReadyState == 4 && jsonData.Status == 200) {
.... process response
}
}
function messageRouterRun() {
var request = {
"method": "GET",
"url": "/democontroller/movies",
"parameters": null,
"postData": null,
};
window.cefQuery({
request: JSON.stringify(request),
onSuccess: function (response) {
messageRouterResult(response);
}, onFailure: function (err, msg) {
console.log(err, msg);
}
});
}
Where:
On success callback function: messageRouterResult
Chromely
Getting Started
The Basics
Digging Deeper
- Sub-Process
- Infrastructure
- Restful Resources
- Register Resource Assemblies
- Custom Local Resource Handling
- Custom Scheme Handling
- Expose .NET class to JavaScript
- Generic Message Routing
- Real-time with Websocket
- External Url Registration
Angular - React - Vue