|
|
|
|
|
- Calling a REST function programmatically
- Secure REST web service
- Examples
- Simple examples
- Examples of access to a secure REST web service
REST web service: Calling a web service function
Not available
Calling a REST function programmatically RESTSend is used to call a function of a REST web service. To do so, you must: - Use a variable of type restRequest to describe the REST function to call. The main available properties are as follows:
- The URL property describes the address (URL) of the REST web service function.
- The Method property describes the HTTP method used (GET, PUT, etc.).
- The ContentType property describes the type of data to be passed as a parameter to the REST web service function.
- The Content property contains the data to be sent as a parameter to the REST web service function.
- Any parameters to be passed.
- Use a variable of type restResponse to retrieve the result of the REST function:
- The StatusCode property gets the response status code.
- The Content property contains the response data.
Note: If a secure REST web service is used, you will need to use the AuthToken property. Secure REST web service To use a function of a secure REST web service: - Log in via OpenID or OAuth to retrieve the identification and authorization token.
- Use the token when sending the request to the REST web service.
Simple examples - The following code shows how to retrieve information about a customer identified by a number. A 200 status code is returned if the customer does not exist.
nCustomerNum is int
nCustomerNum= 2
h is httpRequest
h.Method = httpGet
h.URL = "http://localhost/V1/Customers/" + nCustomerNum
r is httpResponse = RESTSend(h)
IF r.StatusCode = 200 THEN
Info(r.Content)
ELSE
Info("Customer not found", r.Content)
END
- The following code shows how to delete a customer identified by a number. A 404 status code is returned if the customer does not exist.
nCustomerNum is int
nCustomerNum= 267
h is httpRequest
h.Method = httpDelete
h.URL = "http://localhost/V1/Customers/" + nCustomerNum
r is httpResponse = RESTSend(h)
IF r..StatusCode = 404 THEN
Info("Customer NOT found.")
ELSE
Info("The customer was successfully deleted")
END
- The following example explains how to add a customer. A 201 status code is returned if the customer was successfully added.
NewCust is Buffer
vCust is Variant
vCust.CustomerName = "MOORE"
vCust.Company = "MOORE Ltd"
vCust.City = "LONDON"
NewCust = VariantToJSON(vCust)
h is httpRequest
h.Method = httpPost
h.URL = "http://localhost/V1/Clients"
h.ContentType = "application/json"
h.Content = NewCust
r is httpResponse = RESTSend(h)
IF r.StatusCode = 201 THEN
Info(r.Content)
ELSE
Info("Error while creating customer", r.Content)
END
Examples of access to a secure REST web service Example of secure login using OpenID. Once retrieved, the token can be used in the AuthToken property of the restRequest variable. openid_param is OpenIDParameters
openid_param.ConfigurationURL = "http://localhost/.well-known/openid-configuration"
openid_param.ClientID = "01234567-89ab-cdef-0123-456789abcdef"
openid_param.ClientSecret = "fedcba98-7654-3210-fedc-ba9876543210"
openid_param.Scope = "read"
openid_param.GrantType = gtAuthorizationCode
let token = AuthIdentify(openid_param)
IF NOT token.Valid THEN
IF ErrorOccurred THEN
Info(ErrorInfo(errFullDetails))
ELSE
Info("Invalid token")
END
RETURN
END
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|