Chameleon API
chm.FindRoute
This procedure finds a route in chameleon.Routes
table that matches given request (URL and http method).
CREATE PROCEDURE [chm].[FindRoute]
(
@context_id INT NULL,
@path NVARCHAR(4000) NULL,
@httpMethod NVARCHAR(10) NULL,
@debug BIT NULL
)
It is mainly used by RoutingMiddleware.
After execution, it selects a list of route values for the parameters that the matched route may have had. The selected recordset also contains two system items named $route_id
and $route_sproc
that specify id
of matched route and name of controller stored procedure respectively.
Schema of returned records are the same as chameleon._routeValues table. This, chm.FindRoute
can be used to fill this table.
Example:
declare @path nvarchar(1000)
declare @HttpMethod varchar(10)
select @path = [path] from chameleon._requestUrl where [context_id] = @context_id
select @HttpMethod = [method] from chameleon._request where [context_id] = @context_id
insert into chameleon._routeValues(context_id, name, value, isDefault)
exec chm.FindRoute @context_id, @path, @HttpMethod, 0
chm.GetFileParts
This function receives a file's relative or abosulte path, extracts details of the file and return them as a table record.
Signature:
CREATE OR ALTER FUNCTION chm.GetFileParts(@filePathAndName nvarchar(max), @unixPaths bit)
RETURNS TABLE
(
[root] nvarchar(100),
[path] nvarchar(4000),
[fullName] nvarchar(550),
[name] nvarchar(500),
[extension] nvarchar(50)
)
The @unixPaths
parameter tells GetFileParts()
to generate file path in unix format, i.e., a paths with slash / character as separator.
Example 1:
select * from chm.GetFileParts('/js/plugins/jquery.min.js', 1)
/*
| root | path | fullName | name | extension |
+------+-------------+---------------+------------+------------|
| | /js/plugins | jquery.min.js | jquery.min | js |
*/
Example 2:
select * from chm.GetFileParts('c:\source\repos\my-app\index.js', 0)
/*
| root | path | fullName | name | extension |
|------+----------------------+----------+-------+-----------+
| c: | \source\repos\my-app | index.js | index | js |
*/