PxPlus Web Services

Examples - File Access Web Service

Below are examples of File Access Web services that were defined using Web Services Maintenance to create URL-style read and write requests for accessing files.

(Support for defining Web Services for file access was added in PxPlus 2022.)

Simple Read Requests

This is an example of a File Access Web service defined for a simple read request.

The Function parameter is set to Read, and then the Dir, Dict and Type parameters are defined. For URL Order and the Allow Override? check box, the default settings can be left as is. The enabling of OAuth2 Security is optional.

GET Request Format

The following format runs the File Access Web service for a simple read request:

GET "http://localhost:8080/do/service_name/table/key"

Example:

call "*plus\web\request","http://localhost:8080/do/read/states/ON ","",resp$,resphdr$

If desired, additional parameters, such as kno, beg_key, end_key, and filter, can be manually added.

Full Read Request

The possible parameters for a full read request are function, dir, dict, table, kno, key, beg_key, end_key, filter and type. Valid types are JSON, XML and CSV.

GET Request Format

The following format runs the File Access Web service for a full read request:

GET "http://localhost:8080/services/fileaccess.pxp?function=read&dir=data_path&dict=dict&table=table_name&beg_key=key&end_key=key&filter=filter&type=output_type"

Example:

call "*plus\web\request","http://localhost:8080/services/fileaccess.pxp?function=read&dir=C%3A\Users\User\workspace\data&dict=providex.ddf&table=states&beg_key=NC&end_key=NY&filter= taxrate%3C5&type=JSON","",resp$,resphdr$

Using Web Services Maintenance, you can easily define a File Access Web service for a read request. Set the Function to Read, and then define any parameters to pre-set. Specify any parameters to override by selecting the Allow Override? check box. You must define this to enable OAuth2 security.

GET Request Format

GET "http://localhost:8080/services/service.pxp?id=service_name&table=table_name&beg_key=key&end_key=key&filter=filter"

Example:

call "*plus\web\request","http://localhost:8080/services/service.pxp?id=read&table=states&kno=%231&key=New%20York&type=XML","",resp$,resphdr$

Simple Write Requests

This is an example of a File Access Web service defined for a simple write request.

The Function parameter is set to Write, and then the Dir, Dict and Type parameters are defined. For URL Order and the Allow Override? check box, the default settings can be left as is. If you need to write to tables with external keys, set the URL Order and Allow Override? check box for the key parameter. The enabling of OAuth2 Security is optional.

POST Request Format

The following formats run the File Access Web service for a simple write request:

POST "http://localhost:8080/do/service_name/table/data"
POST "http://localhost:8080/do/service_name/table/key/data" (External Key Write)

Example:

call "*plus\web\request;post","http://localhost:8080/do/write/states/NP%8ANew%20Province%8ACanada%8A13","",resp$,resphdr$

Full Write Requests

POST Request Format

The following format, with the write request as the POST data, runs the File Access Web service for a full write request (see Write Request Format):

POST "http://localhost:8080/services/fileaccess.pxp?function=write&dir=data_path&dict=dict"

Write Request Format

For POST request data, the valid request types are Insert, Update and Remove. The request can be in JSON or XML:

JSON:
{ "requests":[
    {"type":"insert"|"remove"|"update",
     "table":"table_name",
     "key":"key_data",     (Optional. Required only for tables with an external key.)
     "data":[
         {"field_name ":"field_data",
              (All fields from the table are included here.)
    ]
    },     (Multiple requests can be included. A comma is required only if there is another request.)
]
}
XML:
<root>
<requests>
<request>
<type>insert|remove|update</type>
<table>tablename</table>
<key>key_data</key>     (Optional. Required only for tables with an external key.)
<data>
<field_name>field_data</field_name>
     (All fields from the table are included here.)
</data>
</request>
     (Multiple requests can be included.)
</requests>
</root>

Example:

dim writeRequest$
writeRequest$["requests.1.type"]="insert"
writeRequest$["requests.1.table"]="states"
writeRequest$["requests.1.data.1.stateCode$"]="AY"
writeRequest$["requests.1.data.1.stateName$"]="Anywhere"
writeRequest$["requests.1.data.1.country$"]="Canada"
writeRequest$["requests.1.data.1.taxRate"]="6"
writeRequest$["requests.1.data.2.stateCode$"]="AW"
writeRequest$["requests.1.data.2.stateName$"]="A&W Burgers"
writeRequest$["requests.1.data.2.country$"]="Canada"
writeRequest$["requests.1.data.2.taxRate"]="20"
writeRequest$["requests.2.type"]="update"
writeRequest$["requests.2.table"]="states"
writeRequest$["requests.2.data.1.stateCode$"]="AW"
writeRequest$["requests.2.data.1.stateName$"]="A&W Burgers and Root Beer"
writeRequest$["requests.2.data.1.country$"]="Canada"
writeRequest$["requests.2.data.1.taxRate"]="18"
writeRequest$["requests.3.type"]="remove"
writeRequest$["requests.3.table"]="states"
writeRequest$["requests.3.key"]="AY"
json$=dim(list edit writeRequest${all})
call "*plus\web\request","http://localhost:8080/services/fileaccess.pxp?function=write&dir=C%3A\Users\User\workspace\data&dict=providex.ddf",json$,resp$,resphdr$,"application/json","",""

Using Web Services Maintenance, you can easily define a File Access Web service for a write request. Set the Function to Write, and then define any parameters to pre-set. Specify any parameters to override by selecting the Allow Override? check box. You must define this to enable OAuth2 security.

POST Request Format

POST "http://localhost:8080/services/service.pxp?id=write"

Example:

call "*plus\web\request","http://localhost:8080/services/service.pxp?id=write",json$,resp$,resphdr$,"application/json","",""

See Also

Web Services
Web Services Maintenance