I'm working on an api server and needed a way to grab parameters from the
url by their placement.
i.e., from "/api/people/uuid/" I want the table name and the uuid.
If I received /api/?table=people&id=uuid then 4D's Web Get Variables would
work just fine.
So, I came up with this (cribbed from the 4D Docs on *Match regex*(:
*C_TEXT*($text;$match;$key)
*C_BOOLEAN*($found)
$text:="/api/people/E862F2A87B4A453087D794576B7E51B0/"
$match:="/api/(\\w+)/(\\w+)/"
*ARRAY LONGINT*($position_found_array;0)
*ARRAY LONGINT*($length_found_array;0)
$found:=*Match regex*($Match;$text;1;$position_found_array;
$length_found_array)
*If *($found)
$table_name:=*Substring*($text;$position_found_array{1};$length_found_array
{1})
*If *(*Size of array*($position_found_array)>=2)
$key:=*Substring*($text;$position_found_array{2};$length_found_array{2})
*End if *
*End if *
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************