Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Registering Url Schemes

Fiahblade edited this page Jan 24, 2020 · 2 revisions

Chromely centralizes and control all url requests via a url scheme. A registered url determines what Chromely does with it. An unregistered scheme will follow default behavior or a behavior pre-programmed by the developer.

There are 4 types of schemes (provided by UrlSchemeType).

  • Resource
  • Custom (usually http used for IPC)
  • Command
  • External

Resource Url Scheme

A resource url scheme is needed to register a custom resource handler. For details please see Registering Resource Handlers.

Custom Url Scheme

A custom url scheme is needed to register a custom http scheme handler. For details please see Registering Custom Scheme Handlers.

Command Url Scheme

A command url scheme is needed to register command routes. A command is a fire-and-forget event trigger. It is different from an action route because no response/data is returned. For details please see Command Routes.

External Url Scheme

An external url scheme is needed to register external urls. When an external url is triggered, it is opened in the default OS browser.

See examples below.

Every scheme is registered via a UrlScheme object.

Property Description Comment
Name The name identifies the scheme. This is required for Custom schemes. The name matches the key used to register a custom handler in IOC container.
Scheme The scheme. For example: http, https, cmd etc.
Host The host. For example: chromely.com, me.com, command.com.
BaseUrl The base url. With base url, the scheme and host can be deduced. Base ul is also required if a BaseUrlStrict is set to true. Sample base urls are https://github, http://chromely.com
UrlSchemeType The scheme type. Types are Resource, Custom, Command, External
BaseUrlStrict The BaseUrlStrict determines the strictness of the BaseUrl. This is mostly used for External url schemes. If the BaseUrl is https://github.com/chromelyapps/Chromely and BaseUrlStrict is "true" only url from the base and beyond will be processed - https://github.com/chromelyapps/Chromely and https://github.com/chromelyapps/Chromely/external will be valid. https://github.com will be ignored.

You can register a url scheme either in config file or via C# code.

  • Using config file
"urlSchemes": [
    {
      "name": "default-resource",
      "baseUrl": "",
      "scheme": "local",
      "host": "",
      "urlSchemeType": "resource",
      "baseUrlStrict": false
    },
    {
      "name": "default-custom-http",
      "baseUrl": "",
      "scheme": "http",
      "host": "chromely.com",
      "urlSchemeType": "custom",
      "baseUrlStrict": false
    },
    {
      "name": "default-command-http",
      "baseUrl": "",
      "scheme": "http",
      "host": "command.com",
      "urlSchemeType": "command",
      "baseUrlStrict": false
    },
    {
      "name": "chromely-site",
      "baseUrl": "https://github.com/chromelyapps/Chromely",
      "scheme": "",
      "host": "",
      "urlSchemeType": "external",
      "baseUrlStrict": true
    }
]
  • Using C# code
public class DefaultConfiguration : IChromelyConfiguration
{
    public DefaultConfiguration()
    {
        UrlSchemes.AddRange(new List<UrlScheme>()
        {
            new UrlScheme("default-resource", "local", string.Empty, string.Empty, UrlSchemeType.Resource, false),
            new UrlScheme("default-resource", "local", string.Empty, string.Empty, UrlSchemeType.Resource, false),
            new UrlScheme("default-custom-http", "http", "chromely.com", string.Empty, UrlSchemeType.Custom, false),
            new UrlScheme("default-command-http", "http", "command.com", string.Empty, UrlSchemeType.Command, false),
            new UrlScheme("chromely-site", string.Empty, string.Empty, "https://github.com/chromelyapps/Chromely", UrlSchemeType.External, true)
        });
        
    }
}