Below are some examples of PSP pages performing RPC requests. A typical server-side PSP script taking care of a RPC request has the form:

<!DOCTYPE html>
<html xmlns:psp="http://www.prologwebservices.org/psp" psp:prolog="

The page loads Prolog databases located on the remote server that are supposed to be relevant to the goal sent via the RPC request. Notice that any output given during the processing of the RPC request on the server-side is suppressed. It is recommended to place the Prolog code in the html tag.

Example 1: Fill a table with RPC data

Let's assume that a remote web service stores a dynamic database about currency rates. The server provides a exchange_rate/3 predicate with mode exchange_rate(+BaseCurrencyCode, +TargetCurrencyCode, -ExchangeRate). A client PSP page receiving the target currency code (i.e. base) and filling a table with eschange rates relative to it can be written as:

<!DOCTYPE html>
<html xmlns:psp="http://www.prologwebservices.org/psp" psp:prolog="
http_parameters(Request, [base(Base, [default('USD')])]),
URL = 'http://localhost/psp/exchange_rates_server.psp',
http_findall(Code-Name, URL:currency(Code, Name, _), List)
<b psp:prolog="format('Exchange Rates (Base Currency: ~w)', [Base])"></b>
<form method="get" action="">
<select required="required" name="base" psp:prolog="
select(Code-Name, List, _),
(Code = Base -> Selected = 'selected' ; Selected = false)
psp:selected="Selected \= false, write(Selected)"
psp:prolog="format('~w (~w)', [Name, Code])">
<input type="submit" value="Submit">
<table psp:prolog="http_call(URL:(currency(Code, Name, _), exchange_rate(Base, Code, Rate)))">
<td psp:prolog="write(Code)"></td>
<td psp:prolog="write(Name)"></td>
<td psp:prolog="write(Rate)"></td>
Last update: Mon Nov 02 00:37:21 2015