Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Universal REST Simulator is a universal simulator for REST APIs. This simulator can be configured by adding some configuration files into the config directory. Universal REST Simulator can read all files with the extension .

NotificationsYou must be signed in to change notification settings

kamshory/Universal-REST-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

200 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Universal REST Simulator is a universal simulator for REST APIs. This simulator can be configured by adding some configuration files into theconfig directory. Universal REST Simulator can read all file extensions.

The configuration is similar to thethis file. If the configuration value is more than one line, then the value in the line other than the last must end with\ (backslash).

The tutorial can be read athttps://github.com/kamshory/Universal-REST-Simulator/blob/main/tutorial.md

Example:

PARSING_RULE=\$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no\$INPUT.REF_NUMBER=$REQUEST.refno\$INPUT.ACCEPT_LANGUAGE=$OUTPUT.HEADER.ACCEPT_LANGUAGE\$INPUT.AMOUNT=$REQUEST.amount

ThePARSING_RULE property above consists of 4 lines. If the\ character is omitted, thenPARSING_RULE has no value. If the\ in line 2 is omitted it becomes as follows:

PARSING_RULE=\$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no$INPUT.REF_NUMBER=$REQUEST.refno\$INPUT.AMOUNT=$REQUEST.amount

thenPARSING_RULE only consists of 2 lines, namely:

$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no

Because after the line loses\ at the end, the simulator will not continue reading the data. This configuration method applies to all properties.

Path

Property:PATH

Universal REST Simulator will select the configuration according to thepath which is accessed by the same method as the request method. For example: user creates 7 configuration files, Universal REST Simulator will select one file with appropriatepath. After getting a file with the appropriate path and method, the simulator will stop looking for other files.

Example configuration file structure:

[root]    [config]        config1.txt        config2.txt        config3.txt

root is the document root of the simulatorconfig is a directory under document rootThe filesconfig1.txt,config2.txt,config3.txt are in theconfig directory.

If thePATH in theconfig1.txt file is/biller/config1, then the file will be selected only if the path in the request URL is/biller/config1. If thePATH in theconfig2.txt file is/bank/config2, then the file will be selected only if the path in the request URL is/bank/config2. If none of the files withpath match, then the simulator will give no response.

Method

Property:METHOD

User can chooseGET,POST orPUT method. Universal REST Simulator will read the request according to the method used in the configuration and will ignore other requests.

Content Type

Content Type Request

Property:REQUEST_TYPE

Universal REST Simulator supports 3 kinds ofcontent types which are as follows:

  1. application/x-www-form-urlencoded
  2. application/json
  3. application/xml
  4. application/soap+xml

Thiscontent type will affect how to read requests on the simulator.

Content Type Response

Property:RESPONSE_TYPE

Users are free to use any content type for the response because basically the response simulator is pure text.

Input Configuration

Property:PARSING_RULE

$INPUT is an object that can be thought of as a global variable and has properties.$INPUT is always capitalized. The property of$INPUT can be written in both uppercase and lowercase letters and will becase sensitive.

Input comes from 2 sources namely$REQUEST (request body inPOST andPUT andquery string inGET) and$OUTPUT.HEADER (request header). Both$REQUEST and$OUTPUT.HEADER must be capitalized. The property name of$REQUEST iscase sensitive while the property name of$OUTPUT.HEADER is capitalized and- is changed to_. This is because the header properties may have changed and cannot be predicted with certainty.

$REQUEST can come from:

  1. Query onGET
  2. Request body onPOST andPUT
  3. Wildcard URL
  4. Basic Authorization

To retrieve$REQUEST from a URL wildcard, simply use{[IDENTIFIER]} in the URL.{[IDENTIFIER]} iscase sensitive.

Example:

PATH=/payment/{[PRODUCT_CODE]}/{[CUSTOMER_ID]}/{[REFERENCE_NUMBER]}

If the client requests eitherGET,POST orPUT with URL/payment/123/456/7890, then$REQUEST.PRODUCT_CODE will be123,$REQUEST.CUSTOMER_ID will be value456,$REQUEST.REFERENCE_NUMBER will be7890. URL wildcards can still be concatenated with query strings. Both the input from the URL wildcard and the query string can be parsed in a single request.

Basic authorization contains a username and password to access a data source. The username and password information is encoded with base 64. The simulator extracts the information and then saves it to the$AUTHORIZATION_BASIC object.

To retrieve the username from basic authorization, use$AUTHORIZATION_BASIC.USERNAME. To retrieve the password from basic authorization, use$AUTHORIZATION_BASIC.PASSWORD.$AUTHORIZATION_BASIC.USERNAME and$AUTHORIZATION_BASIC.PASSWORD must be capitalized.

The simulator reads the input depending on thecontent type request. Forcontent typeapplication/x-www-form-urlencoded, the simulator directly fetches the value of the appropriate parameter. Forapplication/json andapplication/xml content types, the simulator will fetch data incrementally. Thus, users are free to provide JSON and XML requests with a nested structure.

The input matrix and methods of Universal REST Simulator are as follows:

MethodContent TpeData SourceAlternative Object
GETapplicatiom/x-www-form-urlencodedHeader, URL,
Basic Authorization,
GET
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET
POSTapplicatiom/x-www-form-urlencodedHeader, URL, Body,
Basic Authorization,
GET, POST
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET,$POST
POSTapplicatiom/jsonHeader, URL, Body,
Basic Authorization,
GET
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET
POSTapplicatiom/xmlHeader, URL, Body,
Basic Authorization,
GET
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET
POSTapplicatiom/soap+xmlHeader, URL, Body,
Basic Authorization,
GET
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET
PUTapplicatiom/x-www-form-urlencodedHeader, URL, Body,
Basic Authorization,
GET, PUT
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET,$PUT
PUTapplicatiom/jsonHeader, URL, Body,
Basic Authorization,
GET
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET
PUTapplicatiom/xmlHeader, URL, Body,
Basic Authorization,
GET
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET
PUTapplicatiom/soap+xmlHeader, URL, Body,
Basic Authorization,
GET
$HEADER,$URL,$REQUEST,
$AUTHORIZATION_BASIC,
$GET

Input from Objects and Arrays

Users may use a combination ofarray andobject as thepayload of therequest eitherGET,POST,PUT, orREQUEST. To retrieve values from input which are allobject, you can use the dot operator (.) while to retrieve values from input which is a combination ofobject andarray, you can use the square bracket operator[].

Payload Example

{"items":[{"name":"Kopi","amount":15000},{"name":"Roti","amount":80000}],"customer": {"name":"Anonim","phone":"081111111111111"}}

Example Configuration

PATH=/universal-rest-simulator/arrayMETHOD=POSTREQUEST_TYPE=application/jsonRESPONSE_TYPE=text/plainPARSING_RULE=\$INPUT.AMOUNT0=$REQUEST[items][0][amount]\$INPUT.AMOUNT1=$REQUEST[items][1][amount]\$INPUT.NAME0=$REQUEST[items][0][name]\$INPUT.NAME1=$REQUEST[items][1][name]TRANSACTION_RULE=\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=\NAMA ITEM    : $INPUT.NAME0\HARGA ITEM   : $INPUT.AMOUNT0\NAMA ITEM    : $INPUT.NAME1\HARGA ITEM   : $INPUT.AMOUNT1\$INPUT.PARAMS\{[ENDIF]}

The[] operator can be used to retrieve values fromobject andarray. It is not allowed to combine the. and[] operators in retrieving a value. Thus, writing$INPUT.AMOUNT0=$REQUEST[items][0].amount is not allowed. However, it is permissible to use their combination on different inputs.

Example of Operator Combinations

PATH=/universal-rest-simulator/arrayMETHOD=POSTREQUEST_TYPE=application/jsonRESPONSE_TYPE=text/plainPARSING_RULE=\$INPUT.CUSTOMER_NAME=$REQUEST.customer.name\$INPUT.AMOUNT0=$REQUEST[items][0][amount]\$INPUT.AMOUNT1=$REQUEST[items][1][amount]\$INPUT.NAME0=$REQUEST[items][0][name]\$INPUT.NAME1=$REQUEST[items][1][name]TRANSACTION_RULE=\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=\NAMA PELANGGAN : $INPUT.CUSTOMER_NAME\NAMA ITEM      : $INPUT.NAME0\HARGA ITEM     : $INPUT.AMOUNT0\NAMA ITEM      : $INPUT.NAME1\HARGA ITEM     : $INPUT.AMOUNT1\$INPUT.PARAMS\{[ENDIF]}

$INPUT.CUSTOMER_NAME=$REQUEST.customer.name can also be written as$INPUT.CUSTOMER_NAME=$REQUEST[customer][name] without spaces before[ and after].

Value of UUID

Universal REST Simulator allows the use of UUIDs. To retrieve the UUID from the system, use$SYSTEM.UUID.

Example:

$INPUT.UUID=$SYSTEM.UUID\$INPUT.RANDOM_ID=$SYSTEM.UUID\$INPUT.UNIQ_ID=$SYSTEM.UUID

From the example above,$INPUT.UUID,$INPUT.RANDOM_ID, and$INPUT.UNIQ_ID will have different values.

Examples of Encoded URL Input Configuration

PATH=/biller/config1METHOD=POSTREQUEST_TYPE=application/x-www-form-urlencodedRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no\$INPUT.REF_NUMBER=$REQUEST.refno

In the above configuration,$INPUT.PRODUCT will retrieve the value from$REQUEST.product_code. Thus, when a user makes a request with the URL/biller/config1?product_code=10000&customer_no=081266612126&refno=5473248234, then$INPUT.PRODUCT will be worth10000, and$INPUT.ACCOUNT will be081266612126 etc.

Examples of JSON Input Configuration

PATH=/bank/config2METHOD=POSTREQUEST_TYPE=application/jsonRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.COMMAND=$REQUEST.command\$INPUT.PRODUCT=$REQUEST.data.destination_bank_code\$INPUT.ACCOUNT=$REQUEST.data.beneficiary_account_number\$INPUT.REF_NUMBER=$REQUEST.data.customer_reference_number

JSON is usually used inPOST orPUT methods. In the above configuration,$INPUT.PRODUCT will take the value from$REQUEST.data.destination_bank_code which isROOT.data.destination_bank_code. whereROOT is a JSON object. Thus, when a user makes a request with

POST /bank/config2 HTTP/1.1 Host: 127.0.0.1Content-type: application/jsonContent-length: 166{"command":"inquiry","data":{"destination_bank_code":"002","beneficiary_account_number":"1234567890","customer_reference_number":"9876544322"}}

then$INPUT.PRODUCT will be worth002, likewise$INPUT.ACCOUNT will be1234567890 and so on.

Contoh Konfigurasi Input XML

PATH=/bank/config3METHOD=POSTREQUEST_TYPE=application/xmlRESPONSE_TYPE=application/xmlPARSING_RULE=\$INPUT.COMMAND=$REQUEST.command\$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no\$INPUT.AMOUNT=$REQUEST.amount\$INPUT.REF_NUMBER=$REQUEST.refno

XML is usually used inPOST orPUT methods. In the above configuration,$INPUT.PRODUCT will take the value from$REQUEST.product_code which isROOT.product_code. whereROOT is the first level tag of the XML. Thus, when a user makes a request with

POST /bank/config3 HTTP/1.1 Host: 127.0.0.1Content-type: application/xmlContent-length: 196<?xml  version="1.0"  encoding="UTF-8"?><data>    <command>inquiry</command>    <product_code>10001</product_code>    <customer_no>081266612127</customer_no>    <amount>5000000</amount>    <refno>123456443</refno></data>

then$INPUT.PRODUCT will be worth10001, likewise$INPUT.ACCOUNT will be081266612127 and so on.

Combination of GET+POST and GET+PUT

Universal REST Simulator can combineGET input withPOST orPUT. To combineGET withPOST, use thePOST method. To combineGET withPUT, use thePUT method.

POST andPUT only apply toREQUEST_TYPE=application/x-www-form-urlencoded . In this case, the client must also sendContent-type: application/x-www-form-urlencoded. Taking input fromGET,POST, andPUT is the same asREQUEST as in the following example:

PATH=/universal-simulator/tokenMETHOD=POSTREQUEST_TYPE=application/x-www-form-urlencodedRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.USERNAME=$AUTHORIZATION_BASIC.USERNAME\$INPUT.PASSWORD=$AUTHORIZATION_BASIC.PASSWORD\$INPUT.GRANT_TYPE=$POST.grant_type\$INPUT.DETAIL=$GET.detail\$INPUT.UUID1=$SYSTEM.UUID\$INPUT.UUID2=$SYSTEM.UUID\$INPUT.UUID3=$SYSTEM.UUID\$INPUT.UUID4=$SYSTEM.UUIDTRANSACTION_RULE=\{[IF]} ($INPUT.GRANT_TYPE =='client_credentials' && $INPUT.USERNAME =="username" && $INPUT.PASSWORD =="password" && $INPUT.DETAIL =="yes")\{[THEN]} $OUTPUT.DELAY=0\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"token_type":"Bearer",\"access_token":"$TOKEN.JWT",\"expire_at": $TOKEN.EXPIRE_AT,\"expires_in": $TOKEN.EXPIRE_IN,\"econfig1l":"token@doconfig1n.tld"\}\{[ENDIF]}\{[IF]} ($INPUT.GRANT_TYPE =='client_credentials' && $INPUT.USERNAME =="username" && $INPUT.PASSWORD =="password")\{[THEN]} $OUTPUT.DELAY=0\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"token_type":"Bearer",\"access_token":"$TOKEN.JWT",\"expire_at": $TOKEN.EXPIRE_AT,\"expires_in": $TOKEN.EXPIRE_IN\}\{[ENDIF]}\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"token_type":"Bearer",\"access_token":"$TOKEN.JWT",\"expire_at": $TOKEN.EXPIRE_AT,\"expires_in": $TOKEN.EXPIRE_IN\}\{[ENDIF]}\

The configuration above shows that the path requires thePOST method and others. However, users can still retrieve values from queries atURL using$GET.

Sample Request

POST /universal-simulator/token?detail=yes HTTP/1.1 Host: 127.0.0.1Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=Content-type: application/x-www-form-urlencodedContent-length: 29grant_type=client_credentials

From the example above, the input from the URL/universal-simulator/token?detail=yes is taken with$GET.detail. This value will be equal to$REQUEST.detail if using theGET method. Because the configuration has definedMETHOD=POST, this value can only be retrieved with$GET.detail because$REQUEST only refers to the request body sent.

Retrieval of data from the body can be done in two ways, namely$REQUEST and$POST. Note that$POST can only be used ifREQUEST_TYPE=application/x-www-form-urlencoded andContent-type: application/x-www-form-urlencoded. For other content types, must use$RQUEST.

$CALC() Function

The$CALC() function is very useful for performing mathematical operations where$INPUT is one of the operands.

For example: the user will add the bill amount with admin fee. If the invoice is stored in the variable$INPUT.AMOUNT and the admin fee is stored in the variable$INPUT.FEE, it can be written as$CALC($INPUT.AMOUNT + $INPUT.FEE). If the admin fee is a fixed value of 2500, it can be written as$CALC($INPUT.AMOUNT + 2500).

The$CALC() function can also calculate formulas in brackets. Example:$CALC($INPUT.AMOUNT + $INPUT.FEE + ($INPUT.AMOUNT * 10/100)) and so on. Note that the number of opening brackets must equal the number of closing brackets.

PATH=/biller/post/jsonMETHOD=POSTREQUEST_TYPE=application/jsonRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no\$INPUT.REF_NUMBER=$REQUEST.refno\$INPUT.AMOUNT=$REQUEST.amount\$INPUT.FEE=$REQUEST.admin_feeTRANSACTION_RULE=\{[IF]} ($INPUT.PRODUCT =="322112" && $INPUT.FEE > 0)\{[THEN]} $OUTPUT.DELAY=0\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"rc":"00",\"description":"Success",\"mitra_code":"904",\"product_code":"322112",\"merchant_type":"5612",\"customer_no":"$INPUT.ACCOUNT",\"product_name":"GOPAY",\"phone_number":"$INPUT.ACCOUNT",\"name":"GOPAY GP-$INPUT.ACCOUNT",\"amount": $INPUT.AMOUNT,\"admin": $INPUT.FEE,\"total": $CALC($INPUT.AMOUNT + $INPUT.FEE),\"transaction_date":"$DATE('d-m-Y H:i:s', 'UTC+9')",\"transaction_code":"000002873147"\}\{[ENDIF]}\{[IF]} ($INPUT.PRODUCT =="322112")\{[THEN]} $OUTPUT.DELAY=0\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"rc":"00",\"description":"Success",\"mitra_code":"904",\"product_code":"322112",\"merchant_type":"5612",\"customer_no":"$INPUT.ACCOUNT",\"product_name":"GOPAY",\"phone_number":"$INPUT.ACCOUNT",\"name":"GOPAY GP-$INPUT.ACCOUNT",\"amount": $INPUT.AMOUNT,\"admin": 2500,\"total": $CALC($INPUT.AMOUNT + 2500),\"transaction_date":"$DATE('d-m-Y H:i:s', 'UTC+9')",\"transaction_code":"000002873147"\}\{[ENDIF]}\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"rc":"00",\"description":"Success",\"mitra_code":"904",\"product_code":"322112",\"merchant_type":"5612",\"customer_no":"$INPUT.ACCOUNT",\"product_name":"GOPAY",\"phone_number":"$INPUT.ACCOUNT",\"name":"GOPAY GP-$INPUT.ACCOUNT",\"amount": $INPUT.AMOUNT,\"admin": 2500,\"total": $CALC($INPUT.AMOUNT + 2500),\"transaction_date":"$DATE('d-m-Y H:i:s')",\"transaction_code":"000002873147"\}\{[ENDIF]}\

$DATE() Function

The$DATE() function is useful for generating the date and time automatically. The date and time will follow the server time. User can use time zone.

The$DATE() format follows the format in the PHP programming language. The following is an explanation of the$DATE() format in the PHP programming language. To insert a constant character in the$DATE() function, prefix it with\. For example$DATE('Y-m-d\TH:i:s.000\Z', 'UTC+7') will return2020-10:10T20:20:20,000Z. Note that\T will becomeT and\Z will becomeZ.

Format characterDescriptionExample returned values
Day------
dDay of the month, 2 digits with leading zeros01 to 31
DA textual representation of a day, three lettersMon through Sun
jDay of the month without leading zeros1 to 31
l (lowercase 'L')A full textual representation of the day of the weekSunday through Saturday
NISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)1 (for Monday) through 7 (for Sunday)
SEnglish ordinal suffix for the day of the month, 2 charactersst, nd, rd or th. Works well with j
wNumeric representation of the day of the week0 (for Sunday) through 6 (for Saturday)
zThe day of the year (starting from 0)0 through 365
Week------
WISO-8601 week number of year, weeks starting on MondayExample: 42 (the 42nd week in the year)
Month------
FA full textual representation of a month, such as January or MarchJanuary through December
mNumeric representation of a month, with leading zeros01 through 12
MA short textual representation of a month, three lettersJan through Dec
nNumeric representation of a month, without leading zeros1 through 12
tNumber of days in the given month28 through 31
Year------
LWhether it's a leap year1 if it is a leap year, 0 otherwise.
oISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)Examples: 1999 or 2003
YA full numeric representation of a year, 4 digitsExamples: 1999 or 2003
yA two digit representation of a yearExamples: 99 or 03
Time------
aLowercase Ante meridiem and Post meridiemam or pm
AUppercase Ante meridiem and Post meridiemAM or PM
BSwatch Internet time000 through 999
g12-hour format of an hour without leading zeros1 through 12
G24-hour format of an hour without leading zeros0 through 23
h12-hour format of an hour with leading zeros01 through 12
H24-hour format of an hour with leading zeros00 through 23
iMinutes with leading zeros00 to 59
sSeconds with leading zeros00 through 59
uMicroseconds (added in PHP 5.2.2). Note that date() will always generate 000000 since it takes an int parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds.Example: 654321
vMilliseconds (added in PHP 7.0.0). Same note applies as for u.Example: 654
Timezone------
eTimezone identifier (added in PHP 5.1.0)Examples: UTC, GMT, Atlantic/Azores
I (capital i)Whether or not the date is in daylight saving time1 if Daylight Saving Time, 0 otherwise.
ODifference to Greenwich time (GMT) without colon between hours and minutesExample: +0200
PDifference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)Example: +02:00
TTimezone abbreviationExamples: EST, MDT ...
ZTimezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.-43200 through 50400
Full Date/Time------
cISO 8601 date (added in PHP 5)2004-02-12T15:19:21+00:00
r» RFC 2822 formatted dateExample: Thu, 21 Dec 2000 16:01:07 +0200
USeconds since the Unix Epoch (January 1 1970 00:00:00 GMT)See also time()

Sumber:https://www.php.net/manual/en/datetime.format.php

$ISVALIDTOKEN() Function

This function is used in conditions to validate tokens sent viaAuthorization: Bearer. The simulator will fetch the token sent via the header with the keyAuthorization. This token will then be validated according to the server configuration. If the token is true,$ISVALIDTOKEN() will betrue. Otherwise, if the token is false,$ISVALIDTOKEN() will returnfalse. The simulator will only validate tokens generated by the simulator itself.

How to Create Token

In order for the simulator to generate tokens, create a configuration file. The output of the configuration must contain$TOKEN.JWT. Other information such as$TOKEN.EXPIRE_AT and$TOKEN.EXPIRE_IN can also be added.

Configure Request Token

PATH=/authMETHOD=POSTREQUEST_TYPE=application/x-www-form-urlencodedRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.USERNAME=$AUTHORIZATION_BASIC.USERNAME\$INPUT.PASSWORD=$AUTHORIZATION_BASIC.PASSWORD\$INPUT.GRANT_TYPE=$REQUEST.grant_typeTRANSACTION_RULE=\{[IF]} ($INPUT.USERNAME =='username' && $INPUT.PASSWORD =='userpassword' && $INPUT.GRANT_TYPE =='client_credentials')\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"token_type":"Bearer",\"access_token":"$TOKEN.JWT",\"expire_at": $TOKEN.EXPIRE_AT,\"expires_in": $TOKEN.EXPIRE_IN\}\{[ENDIF]}\

How to Validate Token

To do token validation, it's very easy. It is enough to create the condition$ISVALIDTOKEN(). The simulator will take the token sent and validate the token.

Token Validation Configuration

PATH=/Universal-REST-Simulator/va-statusMETHOD=POSTREQUEST_TYPE=application/jsonRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.COMMAND=$REQUEST.command\$INPUT.VA_NUMBER=$REQUEST.data.virtual_account_number\$INPUT.REQUEST_ID=$REQUEST.data.request_id\$INPUT.PG_CODE=$REQUEST.data.pg_code\$INPUT.REF_NUMBER=$REQUEST.data.reference_number\$INPUT.CUST_NUMBER=$REQUEST.data.customer_number\$INPUT.CUST_NAME=$REQUEST.data.customer_name\$INPUT.BANK_CODE=$REQUEST.data.bank_code\$INPUT.CHANNEL_TYPE=$REQUEST.data.channel_type\$INPUT.TOTAL_AMOUNT=$REQUEST.data.total_amount\$INPUT.PAID_AMOUNT=$REQUEST.data.paid_amountTRANSACTION_RULE=\{[IF]} ($INPUT.CUST_NUMBER =="1571200004" && $ISVALIDTOKEN())\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"command":"$INPUT.COMMAND",\"response_code":"00",\"response_text":"Success",\"message": {\"id":"Sukses",\"en":"Success"\    },\"data": {\"bank_code":"$INPUT.BANK_CODE",\"channel_type":"$INPUT.CHANNEL_TYPE",\"pg_code":"$INPUT.PG_CODE",\"merchant_code":"030",\"merchant_name":"Arta Pay",\"virtual_account_number":"$INPUT.VA_NUMBER",\"customer_name":"$INPUT.CUST_NAME",\"request_id":"$INPUT.REQUEST_ID",\"reference_number":"$INPUT.REF_NUMBER",\"time_stamp":"$DATE('Y-m-d\TH:i:s', 'UTC').000Z",\"customer_number":"$INPUT.CUST_NUMBER",\"currency_code":"IDR",\"total_amount": $INPUT.TOTAL_AMOUNT,\"paid_amount": $INPUT.PAID_AMOUNT,\"bill_list": []\    }\}\{[ENDIF]}\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"command":"$INPUT.COMMAND",\"response_code":"05",\"response_text":"Invalid Token",\"message": {\"id":"Sukses",\"en":"Success"\    },\"data": {\"time_stamp":"$DATE('Y-m-d\TH:i:s', 'UTC').000Z"\    }\}\{[ENDIF]}\

The configuration above shows an example of how to validate a token. Note that$INPUT.USERNAME=$AUTHORIZATION_BASIC.USERNAME and$INPUT.PASSWORD=$AUTHORIZATION_BASIC.PASSWORD can no longer be used because theAuthorization key has already been used to send tokens. However, you can still use other keys.

Configure Token Validation with Additional Header

PATH=/Universal-REST-Simulator/va-statusMETHOD=POSTREQUEST_TYPE=application/jsonRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.USERNAME=$HEADER.X_USERNAME\$INPUT.PASSWORD=$HEADER.X_PASSWORD\$INPUT.API_KEY=$HEADER.X_API_KEY\$INPUT.COMMAND=$REQUEST.command\$INPUT.VA_NUMBER=$REQUEST.data.virtual_account_number\$INPUT.REQUEST_ID=$REQUEST.data.request_id\$INPUT.PG_CODE=$REQUEST.data.pg_code\$INPUT.REF_NUMBER=$REQUEST.data.reference_number\$INPUT.CUST_NUMBER=$REQUEST.data.customer_number\$INPUT.CUST_NAME=$REQUEST.data.customer_name\$INPUT.BANK_CODE=$REQUEST.data.bank_code\$INPUT.CHANNEL_TYPE=$REQUEST.data.channel_type\$INPUT.TOTAL_AMOUNT=$REQUEST.data.total_amount\$INPUT.PAID_AMOUNT=$REQUEST.data.paid_amountTRANSACTION_RULE=\{[IF]} ($INPUT.USERNAME =='username' && $INPUT.PASSWORD =='userpassword' && $INPUT.API_KEY =='API123' && $INPUT.CUST_NUMBER =="1571200004" && $ISVALIDTOKEN())\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"command":"$INPUT.COMMAND",\"response_code":"00",\"response_text":"Success",\"message": {\"id":"Sukses",\"en":"Success"\    },\"data": {\"bank_code":"$INPUT.BANK_CODE",\"channel_type":"$INPUT.CHANNEL_TYPE",\"pg_code":"$INPUT.PG_CODE",\"merchant_code":"030",\"merchant_name":"Arta Pay",\"virtual_account_number":"$INPUT.VA_NUMBER",\"customer_name":"$INPUT.CUST_NAME",\"request_id":"$INPUT.REQUEST_ID",\"reference_number":"$INPUT.REF_NUMBER",\"time_stamp":"$DATE('Y-m-d\TH:i:s', 'UTC').000Z",\"customer_number":"$INPUT.CUST_NUMBER",\"currency_code":"IDR",\"total_amount": $INPUT.TOTAL_AMOUNT,\"paid_amount": $INPUT.PAID_AMOUNT,\"bill_list": []\    }\}\{[ENDIF]}\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY={\"command":"$INPUT.COMMAND",\"response_code":"05",\"response_text":"Invalid Token",\"message": {\"id":"Sukses",\"en":"Success"\    },\"data": {\"time_stamp":"$DATE('Y-m-d\TH:i:s', 'UTC').000Z"\    }\}\{[ENDIF]}\

$SYSTEM.RANDOM() Function

Parameter

Optional

integer param1

integer param2

Ifparam1 andparam2 are not present, this function will generate random integer frommt_rand() function on native PHP.

Ifparam1 is present andparam2 is not present, this function will generate random integer frommt_rand(0, abs(param1)) function on native PHP.

Ifparam1 andparam2 are present, this function will generate random integer frommt_rand(min(abs(param1), abs(param2)), max(abs(param1), abs(param2))) function on native PHP.

$JSON.REQUEST() Function

Parameter

Optional

string selector

boolean asText, defaultfalse

Ifselector andasText are not present, this function will return whole request as JSON object.

Ifselector is present andasText is not present, this function will return JSON object from request by selector given.

Ifselector is present andasText is present, this function will return JSON object from request by selector given. IfasText istrue, this function will convert JSON object to string and escape it.

Example Request

{  "transaction_id": "164084965152152228",  "request": {    "data": {      "lastBalance": "59978",      "dateTime": "2017-11-11 10:10:10.123",      "approvalCode": "CCD970377BCD",      "dataToSam": "12121233345454323",      "merchantId": "TESTMID1",      "session": "sessionid123",      "terminalId": "TESTTID1",      "cardNumber": "6032984002487720"    },    "command": "update-balance"  },  "partner_info": {    "partnerID": 80,    "adapterEndpoint": "http://localhost:3000/process-biller"  },  "client_name": "Dora Remitance",  "client_id": 1}

$JSON.REQUEST() or$JSON.REQUEST('') will return JSON object

{  "transaction_id": "164084965152152228",  "request": {    "data": {      "lastBalance": "59978",      "dateTime": "2017-11-11 10:10:10.123",      "approvalCode": "CCD970377BCD",      "dataToSam": "12121233345454323",      "merchantId": "TESTMID1",      "session": "sessionid123",      "terminalId": "TESTTID1",      "cardNumber": "6032984002487720"    },    "command": "update-balance"  },  "partner_info": {    "partnerID": 80,    "adapterEndpoint": "http://localhost:3000/process-biller"  },  "client_name": "Dora Remitance",  "client_id": 1}

$JSON.REQUEST('request') will return JSON object

{    "data": {      "lastBalance": "59978",      "dateTime": "2017-11-11 10:10:10.123",      "approvalCode": "CCD970377BCD",      "dataToSam": "12121233345454323",      "merchantId": "TESTMID1",      "session": "sessionid123",      "terminalId": "TESTTID1",      "cardNumber": "6032984002487720"    },    "command": "update-balance"}

$JSON.REQUEST('request.data') will return JSON object

{"lastBalance": "59978","dateTime": "2017-11-11 10:10:10.123","approvalCode": "CCD970377BCD","dataToSam": "12121233345454323","merchantId": "TESTMID1","session": "sessionid123","terminalId": "TESTTID1","cardNumber": "6032984002487720"}

$JSON.REQUEST('request.data', false) will return JSON object

{"lastBalance": "59978","dateTime": "2017-11-11 10:10:10.123","approvalCode": "CCD970377BCD","dataToSam": "12121233345454323","merchantId": "TESTMID1","session": "sessionid123","terminalId": "TESTTID1","cardNumber": "6032984002487720"}

$JSON.REQUEST('request.data', true) will return string

"{\"lastBalance\":\"59978\",\"dateTime\":\"2017-11-11 10:10:10.123\",\"approvalCode\":\"CCD970377BCD\",\"dataToSam\":\"12121233345454323\",\"merchantId\":\"TESTMID1\",\"session\":\"sessionid123\",\"terminalId\":\"TESTTID1\",\"cardNumber\":\"6032984002487720\"}"

Selection of Conditions

Propety:TRANSACTION_RULE

The simulator only supportsIF and notELSE conditions. All generated data is data that is between{[THEN]} and{[ENDIF]}.IF is written as{[IF]},THEN is written as{[THEN]}, andENDIF is written as{[ENDIF]}. This is to distinguish between reserved words and words that may appear in the configuration data.

The simulator will evaluate the expression on{[IF]}. If the condition evaluates totrue, then the simulator will retrieve all data in that block regardless of whether the condition in the next block istrue orfalse.

Some of the data that can be generated by the simulator are as follows:

  1. $OUTPUT.STATUS is the HTTP status code. The default value of$OUTPUT.STATUS is200
  2. $OUTPUT.HEADER is a line response header.
  3. $OUTPUT.DELAY is the timeout. The server will wait a while before sending a response.
  4. $OUTPUT.BODY is the response body.
  5. $OUTPUT.CALLBACK_URL is the URL that the callback process goes to.
  6. $OUTPUT.CALLBACK_METHOD is the method of the callback. The methods that can be used areGET,POST, andPUT.
  7. $OUTPUT.CALLBACK_TYPE is the content type for the callback. This content type is free as needed.
  8. $OUTPUT.CALLBACK_TIMEOUT is the timeout for the callback.
  9. $OUTPUT.CALLBACK_HEADER is the request header for the callback.
  10. $OUTPUT.CALLBACK_BODY is the request body for the callback.
  11. $OUTPUT.CALLBACK_DELAY is the delay for the callback in milliseconds.

An explanation of callbacks can be read in theCallback section.

PATH=/bank/config2METHOD=POSTREQUEST_TYPE=application/jsonRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.COMMAND=$REQUEST.command\$INPUT.PRODUCT=$REQUEST.data.destination_bank_code\$INPUT.ACCOUNT=$REQUEST.data.beneficiary_account_number\$INPUT.REF_NUMBER=$REQUEST.data.customer_reference_numberTRANSACTION_RULE=\{[IF]} ($INPUT.COMMAND =="inquiry" && $INPUT.PRODUCT =="002" && $INPUT.ACCOUNT =="1234567890")\{[THEN]}\$OUTPUT.STATUS=200\$OUTPUT.DELAY=0\$OUTPUT.BODY=\{\"rc":"00",\"sn":"82634862385235365285",\"nama":"config2",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('j F Y H:i:s', 'UTC+7')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"$INPUT.REF_NUMBER"\}\{[ENDIF]}\{[IF]} ($INPUT.COMMAND =="inquiry" && $INPUT.PRODUCT =="002" && $INPUT.ACCOUNT =="1234567891")\{[THEN]}\$OUTPUT.DELAY=20000\$OUTPUT.BODY=\{\"rc":"00",\"sn":"82634862385235365285",\"nama":"Budi",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('Y-m-d H:i:s')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"873264832658723585"\}\{[ENDIF]}\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=\{\"rc":"25",\"sn":"82634862385235365285",\"nama":"Budi",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('Y-m-d H:i:s')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"873264832658723585"\}\{[ENDIF]}\

The simulator will evaluate the conditions accordingly. If there are two conditions

HTTP Status

The Universal REST Simulator allows the use of non-standard HTTP Status. HTTP Status Standard can be found athttps://developer.mozilla.org/id/docs/Web/HTTP/Status

For standard HTTP Status, users just need to write the code. For example$OUTPUT.STATUS=200 or$OUTPUT.STATUS=403. For use of non-standard HTTP Status, users need to add a description text behind the code. For example:$OUTPUT.STATUS=699 Under Maintenance. If the user does not add a description behind the code, then Universal REST Simulator will send HTTP Status 500 or Internal Server Error.

Example of URL-Encoded Request Configuration

Sample Request

GET /biller/config1?product_code=10000&customer_no=081266612126&refno=5473248234 HTTP/1.1 Host: 127.0.0.1Content-type: application/jsonContent-length: 166

Konfigurasi

PATH=/biller/config1METHOD=POSTREQUEST_TYPE=application/x-www-form-urlencodedRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no\$INPUT.REF_NUMBER=$REQUEST.refnoTRANSACTION_RULE=\{[IF]} ($INPUT.PRODUCT =="10000" && $INPUT.ACCOUNT =="081266612126")\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=\{\"rc":"00",\"sn":"82634862385235365285",\"nama":"config2",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('j F Y H:i:s', 'UTC+7')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"$INPUT.REF_NUMBER"\}\{[ENDIF]}\{[IF]} ($INPUT.PRODUCT =="10000" && $INPUT.ACCOUNT =="081266612127")\{[THEN]}\$OUTPUT.DELAY=20000\$OUTPUT.BODY=\{\"rc":"00",\"sn":"82634862385235365285",\"nama":"Budi",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('Y-m-d H:i:s')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"873264832658723585"\}\{[ENDIF]}\{[IF]} (true)\{[THEN]} $OUTPUT.DELAY=0\$OUTPUT.BODY=\{\"rc":"25",\"sn":"82634862385235365285",\"nama":"Budi",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('Y-m-d H:i:s')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"873264832658723585"\}\{[ENDIF]}\

Example of JSON Request Configuration

On a JSON request, it is possible that thekey of JSON contains characters other thanalpha numeric andunderscore. To allow the simulator to read input from the request, replace all characters other thanalpha numeric andunderscore withunderscore or_.

Contoh Request

POST /bank/config2 HTTP/1.1 Host: 127.0.0.1Content-type: application/jsonContent-length: 166{"command":"inquiry","data":{"destination_bank_code": "002","beneficiary_account_number": "1234567890","customer_reference_number": "9876544322"}}

Konfigurasi

PATH=/bank/config2METHOD=POSTREQUEST_TYPE=application/jsonRESPONSE_TYPE=application/jsonPARSING_RULE=\$INPUT.COMMAND=$REQUEST.command\$INPUT.PRODUCT=$REQUEST.data.destination_bank_code\$INPUT.ACCOUNT=$REQUEST.data.beneficiary_account_number\$INPUT.REF_NUMBER=$REQUEST.data.customer_reference_numberTRANSACTION_RULE=\{[IF]} ($INPUT.COMMAND =="inquiry" && $INPUT.PRODUCT =="002" && $INPUT.ACCOUNT =="1234567890")\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=\{\"rc":"00",\"sn":"82634862385235365285",\"nama":"config2",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('j F Y H:i:s', 'UTC+7')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"$INPUT.REF_NUMBER"\}\{[ENDIF]}\{[IF]} ($INPUT.COMMAND =="inquiry" && $INPUT.PRODUCT =="002" && $INPUT.ACCOUNT =="1234567891")\{[THEN]} $OUTPUT.DELAY=20000\$OUTPUT.BODY=\{\"rc":"00",\"sn":"82634862385235365285",\"nama":"Budi",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('Y-m-d H:i:s')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"873264832658723585"\}\{[ENDIF]}\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=\{\"rc":"25",\"sn":"82634862385235365285",\"nama":"Budi",\"customer_no":"$INPUT.ACCOUNT",\"product_code":"$INPUT.PRODUCT",\"time_stamp":"$DATE('Y-m-d H:i:s')",\"msg":"Transaksi ini dikenakan biaya Rp. 250",\"refid":"873264832658723585"\}\{[ENDIF]}\

Example of XML Request Configuration

Sample Request

POST /bank/config3 HTTP/1.1 Host: 127.0.0.1Content-type: application/xmlContent-length: 196<?xml  version="1.0"  encoding="UTF-8"?><data>    <command>inquiry</command>    <product_code>10001</product_code>    <customer_no>081266612127</customer_no>    <amount>5000000</amount>    <refno>123456443</refno></data>

Configuration

PATH=/bank/config3METHOD=POSTREQUEST_TYPE=application/xmlRESPONSE_TYPE=application/xmlPARSING_RULE=\$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no\$INPUT.REF_NUMBER=$REQUEST.refno\$INPUT.AMOUNT=$REQUEST.amountTRANSACTION_RULE=\{[IF]} ($INPUT.PRODUCT =="10000" && $INPUT.ACCOUNT =="081266612126" && $INPUT.AMOUNT > 0)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=\<?xmlversion="1.0"encoding="UTF-8"?>\<data>\\<rc>00</rc>\<sn>82634862385235365285</sn>\<nama>config2</nama>\<customer_no>$INPUT.ACCOUNT</customer_no>\<product_code>$INPUT.PRODUCT</product_code>\<time_stamp>$DATE('j F Y H:i:s','UTC+7')</time_stamp>\<msg>Transaksi ini dikenakan biaya Rp. 250</msg>\<refid>$INPUT.REF_NUMBER</refid>\<data>\{[ENDIF]}\{[IF]} ($INPUT.PRODUCT =="10001" && $INPUT.ACCOUNT =="081266612127")\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=\<?xmlversion="1.0"encoding="UTF-8"?>\<data>\\<rc>00</rc>\<sn>82634862385235365285</sn>\<nama>config2</nama>\<customer_no>$INPUT.ACCOUNT</customer_no>\<product_code>$INPUT.PRODUCT</product_code>\<time_stamp>$DATE('j F Y H:i:s','UTC+7')</time_stamp>\<msg>Transaksi ini dikenakan biaya Rp. 250</msg>\<refid>$INPUT.REF_NUMBER</refid>\<data>\{[ENDIF]}\{[IF]} (true)\{[THEN]} $OUTPUT.DELAY=0\$OUTPUT.BODY=\<?xmlversion="1.0"encoding="UTF-8"?>\<data>\\<rc>25</rc>\<sn>82634862385235365285</sn>\<nama>config2</nama>\<customer_no>$INPUT.ACCOUNT</customer_no>\<product_code>$INPUT.PRODUCT</product_code>\<time_stamp>$DATE('j F Y H:i:s','UTC+7')</time_stamp>\<msg>Pelanggan tidak ditemukan</msg>\<refid>$INPUT.REF_NUMBER</refid>\<data>\{[ENDIF]}\

Callback

Some simulators send callbacks due to asynchronous processes. Universal REST Simulator also supports callbacks. The callback will be sent after the request has been parsed before delaying response (if any).

To add a callback, some configuration needs to be made onTRANSACTION_RULE which is as follows:

  1. $OUTPUT.CALLBACK_URL is the URL that the callback process goes to.
  2. $OUTPUT.CALLBACK_METHOD is the method of the callback. The methods that can be used areGET,POST, andPUT.
  3. $OUTPUT.CALLBACK_TYPE is the content type for the callback. This content type is free as needed.
  4. $OUTPUT.CALLBACK_HEADER is the request header for the callback.
  5. $OUTPUT.CALLBACK_BODY is the request body for the callback.
  6. $OUTPUT.CALLBACK_DELAY is the delay for the callback in milliseconds.

The default method isGET. If$OUTPUT.CALLBACK_METHOD isGET, then$OUTPUT.CALLBACK_BODY will not be sent and theContent-length andContent-type in headers will also not be sent.

Note that in thePOST andPUT methods, the user must specify$OUTPUT.CALLBACK_BODY because the destination server will wait for the simulator to sendbody to the callback process.$OUTPUT.CALLBACK_TYPE onPOST andPUT must also be set to specifyContent-type on callbacks. Thecontent-length will be generated automatically by the simulator when the callback is made. User can addUser-agent in header. If the user does not enterUser-agent, the simulator will create a defaultUser-agent because some servers may require each request to include aUser-agent.

Configuration

PATH=/universal-rest-simulator/xmlMETHOD=POSTREQUEST_TYPE=application/xmlRESPONSE_TYPE=application/xmlPARSING_RULE=\$INPUT.PRODUCT=$REQUEST.product_code\$INPUT.ACCOUNT=$REQUEST.customer_no\$INPUT.REF_NUMBER=$REQUEST.refno\$INPUT.AMOUNT=$REQUEST.amountTRANSACTION_RULE=\{[IF]} ($INPUT.PRODUCT =="10000" && $INPUT.ACCOUNT =="081266612126" && $INPUT.AMOUNT > 0)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.CALLBACK_URL=http://localhost/test/\$OUTPUT.CALLBACK_METHOD=POST\$OUTPUT.CALLBACK_TYPE=application/xml\$OUTPUT.CALLBACK_HEADER=X-Server-Name: Universal REST Simulator\$OUTPUT.CALLBACK_DELAY=1500\X-Response-Code: 00\X-Response-Text: Success\$OUTPUT.CALLBACK_DELAY=200\$OUTPUT.CALLBACK_BODY=<?xmlversion="1.0"encoding="UTF-8"?>\<data>\\<rc>00</rc>\<sn>82634862385235365285</sn>\<nama>config2</nama>\<customer_no>$INPUT.ACCOUNT</customer_no>\<product_code>$INPUT.PRODUCT</product_code>\<time_stamp>$DATE('j F Y H:i:s','UTC+7')</time_stamp>\<msg>Ini output dari callback Transaksi ini dikenakan biaya Rp. 250</msg>\<refid>$INPUT.REF_NUMBER</refid>\<data>\$OUTPUT.HEADER=X-Server-Name: Universal REST Simulator\X-Response-Code: 00\X-Response-Text: Success\$OUTPUT.BODY=<?xmlversion="1.0"encoding="UTF-8"?>\<data>\\<rc>00</rc>\<sn>82634862385235365285</sn>\<nama>config2</nama>\<customer_no>$INPUT.ACCOUNT</customer_no>\<product_code>$INPUT.PRODUCT</product_code>\<time_stamp>$DATE('j F Y H:i:s','UTC+7')</time_stamp>\<msg>Transaksi ini dikenakan biaya Rp. 250</msg>\<refid>$INPUT.REF_NUMBER</refid>\<data>\{[ENDIF]}\{[IF]} ($INPUT.PRODUCT =="10001" && $INPUT.ACCOUNT =="081266612127")\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=<?xmlversion="1.0"encoding="UTF-8"?>\<data>\\<rc>00</rc>\<sn>82634862385235365285</sn>\<nama>config2</nama>\<customer_no>$INPUT.ACCOUNT</customer_no>\<product_code>$INPUT.PRODUCT</product_code>\<time_stamp>$DATE('j F Y H:i:s','UTC+7')</time_stamp>\<msg>Transaksi ini dikenakan biaya Rp. 250</msg>\<refid>$INPUT.REF_NUMBER</refid>\<data>\{[ENDIF]}\{[IF]} (true)\{[THEN]}\$OUTPUT.DELAY=0\$OUTPUT.BODY=<?xmlversion="1.0"encoding="UTF-8"?>\<data>\\<rc>25</rc>\<sn>82634862385235365285</sn>\<nama>config2</nama>\<customer_no>$INPUT.ACCOUNT</customer_no>\<product_code>$INPUT.PRODUCT</product_code>\<time_stamp>$DATE('j F Y H:i:s','UTC+7')</time_stamp>\<msg>Pelanggan tidak ditemukan</msg>\<refid>$INPUT.REF_NUMBER</refid>\<data>\{[ENDIF]}\

Native PHP Code

In some cases, the simulator cannot be created with a configuration file alone. Processes that are too complex to be handled by programming languages include saving transaction data to a database or file system.

Universal REST Simulator allows users to create their own native PHP code.

This method is actually not recommended because it can harm the simulator. But it can be done if the user understands the PHP language well.

To write native PHP code on the simulator is very easy. First define METHOD and PATH then write PHP code between{[EVAL_PHP_BEGIN]} and{[EVAL_PHP_END]}

Parsing only input data is done manually depending on themethod andcontent-type sent by the client.

Example Configuration

METHOD=POSTPATH=/encrypted/payload/{[EVAL_PHP_BEGIN]}function encryptEBC($key, $payload){    return bin2hex(openssl_encrypt($payload, 'aes-128-ecb', $key, OPENSSL_RAW_DATA));}function decriptEBC($key, $payload){    return openssl_decrypt(hex2bin($payload), 'aes-128-ecb', $key, OPENSSL_RAW_DATA);}$rc = '00';$key = "iY87^R76R%e4d7tD";$clientID = @$_POST['login'];$pwd = @$_POST['pwd'];$terminal = @$_POST['terminal'];$customer = @$_POST['customer'];$trx_date = @$_POST['trx_date'];$trx_type = @$_POST['trx_type'];$sequence_id = @$_POST['sequence_id'];$tx_amount = @$_POST['tx_amount'];$isreversal = @$_POST['isreversal'];$pwd = decriptEBC($key, $pwd);$terminal = decriptEBC($key, $terminal);$customer = decriptEBC($key, $customer);$trx_date = decriptEBC($key, $trx_date);$trx_type = decriptEBC($key, $trx_type);$sequence_id = decriptEBC($key, $sequence_id);if($customer == '0725553725'){    $rc = '00';}header("Content-type: text/plain");echo "$rc:$sequence_id";{[EVAL_PHP_END]}

File Manager

Universal REST Simulator comes with a file manager for creating, modifying and deleting configuration files. The file manager is equipped with a username and password to enter into it. The file manager can be accessed with the path/filemanager/ from the document root of the simulator.

The file manager username and password are stored in the.htpasswd file in thefilemanager directory. Username and password can be added by adding a line at the end of the file. The supported password encryption methods are:

  1. SHA with{SHA} . prefix
  2. APR1 with prefix$apr1$

Usernames and passwords can be generated using the Htpasswd Generator which is widely available online.

A complete guide to using the file manager can be found athttps://github.com/kamshory/PlanetbiruFileManager

Check Path

Universal REST Simulator usespath andmethod to determine which configuration to use. If there are two or more pairs of the samepath andmethod, the configuration file that is found first will be used.

Users need to know whether thepath andmethod have been used or not or whether there is duplication or not. To check thepath andmethod used, the user can simply access /checkpath/ from the document root of the simulator using a browser.

About

Universal REST Simulator is a universal simulator for REST APIs. This simulator can be configured by adding some configuration files into the config directory. Universal REST Simulator can read all files with the extension .

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2026 Movatter.jp