Share this page

# web_rest

Action Functions

Sends a REST API request using any method supported by HTTP.

## C Language

int web_rest( const char *StepName, "URL=<URL>", "Method=<HTML method>", "EncType=<encoding type>","Body=<body of message>" ,"Snapshot=<snapshot file>", [[ITEMDATA [["Name=<name>", "Value|FileName=<value>", ENDITEM,]] ]] [[HEADERS [["Name=<header name>", "Value=<value>", ENDHEADER,]] ]] LAST);

Property Name | Description
--- | ---
The name of the step, as it appears in the graphical script.
URL | The URL of the REST resource.
Method | Any method supported by the HTTP protocol.
EncType | The encoding type. For example, multipart/form_data, application/x-www-form-urlencoded, or raw. If the encoding type is raw, a Content-type header is required. Use only with POST, PUT, DELETE, and OPTIONS methods.
Body | The body of the request.
itemData | Key-value pairs for the data to be POSTed or for URL parameters. If the value is a literal or parameter, the syntax is `Name =<Keyname>, Value = <value expression>`. If the value is in a file, the syntax is `Name =<Keyname>, FileName = <full path name>`.
headers | Header names and values.

## Return Values

This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.

## Parameterization

The values of keyword-value pairs can be parameterized. For example, "ALT={altParam}".

## General Information

The web_rest function is an action function that submits a REST request.

web_rest is not recorded. You can add it manually to a script.

The HTTP header can be modified to pass additional information about the request to the server. Using HTTP headers you can, for example, allow other content types in the response such as compressed files, or you can request a web page only on certain conditions.

The method can be any method supported by the HTTP protocol. For example:

- GET - retrieves a specific Resource from the Server.
- POST - creates a new resource on the server.
- PUT- updates the resource on the server.
- DELETE - removes the resource from the server.
- HEAD -retrieves the meta-data of the resource.
- OPTIONS - retrieves information about actions that are supported for the resource.

## Example 1

This is an example of a post:

    web_rest("POST: www.mysite.com",
       "URL=http://www.mysite?ParamKey1=ParamValue1",
       "Method=POST",
       "EncType=application/x-www-form-urlencoded",
       "Snapshot=t782415.inf",
       ITEMDATA,
          "Name=Key1", "Value=Value1",
            ENDITEM,
          "Name=Key2", "FileName=C:\Program Files (x86)\SAP\FrontEnd\__sap.dir",
            ENDITEM,
       HEADERS,
          Name=Accept", "Value=text/html",
            ENDHEADER,
      LAST);

## Example 2

Examples of web_rest requests for HTTP methods:

Get

    web_rest("get all customers info",
                   "URL=http://myServer/customers?limit={limit}&offset={offset}",
                   "Method=GET",
                   LAST);

Put

    web_rest("update customer info",
                   "URL=http://myServer/customers/{cust_id}",
                   "Method=PUT",
                   "ResType=JSON",
                   "Body={ \"address\":\"yyyy\", … }",
                   LAST);

Post

    web_rest("create new customer",
                   "URL=http://myServer/customers/",
                   "Method=POST",
                   "ResType=JSON",
                   "Body = { \"name\":\"john\", \"address\":\"xxxx\", … }",  /* BodyFile for large content */
                   LAST);

Delete

    web_rest("delete customer",
                   "URL=http://www.example.com/customers/{cust_id}",
                   "Method=DELETE",
                   LAST);

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: