Creating a REST Client

Build a proxy nonvisual user objects that represents a remote Representational State Transfer (REST) service.

Prerequisites
The REST Client Proxy wizard and project require the following installed software:
Task
  1. Click File > New, or open the New dialog box from the toolbar. REST Client Proxy to start the wizard.
  2. From the Project category, select REST Client Proxy. Follow the instructions on each page of the wizard.
  3. In the first page of the wizard, specify the project name and library.
  4. In the Select Service URL page, specify the URL where the service can be accessed on the Web, and the HTTP method action the service uses.
    The action you select also determines the next page the wizard displays:
    Action Next Wizard Page
    HTTP POST or HTTP PUT Specify request message type
    HTTP GET or HTTP DELETE Specify response message type
  5. In the Specify request message type page, choose an action to perform for request messages, and provide any additional information the action requires:
    Option Additional Information Required
    Skip this step None.

    Appropriate for messages that are limited to primitive types and simple arrays.

    Use provided schema/sample data Specify a schema or sample data that PowerBuilder uses to generate an assembly.
    • In the box below, enter or paste the schema, or a sample that instantiates the specified datatype. Or, click the Browse button to choose a file that contains the schema or data.
    • Under Assembly name, specify the name of the assembly to generate. The wizard automatically prefixes the library path.
    Use provided assembly Under Assembly name, specify or select an assembly from the list for the request or response datatype.
    If you choose the second option, PowerBuilder creates the assembly as specified. When the assembly is created successfully, the wizard displays the next page. If the assembly creation fails, the page remains open and displays an error message.
  6. In the Specify request message format and type page:
    • If your service uses no request message, choose a format of None.
    • Otherwise, choose a format and datatype for request messages.
    • Choose the Datatype is array option if appropriate.
    This page is not displayed if the method type is HTTP GET or HTTP DELETE.
  7. In the Specify response message type page, choose an action to perform for response messages, and provide any additional information the action requires:
    Option Additional Information Required
    Skip this step None.

    Appropriate for messages that are limited to primitive types and simple arrays.

    Use provided schema/sample data Specify a schema or sample data that PowerBuilder uses to generate an assembly.
    • In the box below, enter or paste the schema, or a sample that instantiates the specified datatype. Or, click the Browse button to choose a file that contains the schema or data.
    • Under Assembly name, specify the name of the assembly to generate. The wizard automatically prefixes the library path.
    Use provided assembly Under Assembly name, specify or select an assembly from the list for the request or response datatype.
  8. In the Specify response message format and type page:
    • If your service uses no response message, choose a format of None.
    • Otherwise, choose a format and datatype for response messages.
    • Choose the Datatype is array option if appropriate.
  9. In the Specify proxy information page, enter the proxy name, library. Optionally, enter a namespace associated with the proxy.
  10. Click Finish to review the summary page and create the REST client project.
    PowerBuilder .NET generates the project object in the library that you specified in the first wizard page.
  11. Double-click the project to open the Project painter. Use the Project painter to define REST service properties, and, optionally, to change properties you defined in the wizard.
  12. Deploy the project: in the Solution Explorer, right-click the project object and choose Generate Proxy.
    PowerBuilder loads the REST client assembly and creates a proxy NVO that represents a class defined by the service.
  13. At runtime, instantiate the NVO and invoke its function, passing any parameters required to get the result.
    For example:
    test1 svc
    svc = create test1
    int ret
    try
      ret = svc.GetMessage()
      messagebox("ok", ret.ToString())
    catch (System.Exception ee)
      messagebox("Failure", "Error")
    end try