Calls a REST service that returns and optionally expects JSON data. The JSON data is returned as a FoxPro simple value, object or collection.
To call a service you specify the HTTP Verb, plus any optional data to send to the service. You can only pass a single value that is serialized to JSON, but this value can be an object that contains many nested sub-objects or collections. REST services in general accept only a single data object which can contain mutliple sub-objects that act as parameters. How this is set up depends on the service however.
This method expects the service to return a JSON response (
application/json content type) which is turned into a FoxPro value, object or collection that is returned as part of this method.
If the result is an error response (400-599 HTTP Error Codes) you can check
cErrorMsg. If the error result includes JSON and a
.Message property that value is set for the error message.
Errors return a Response Value
CallService()always returns some sort of response - either a string of the raw HTTP buffer, or if the data is
application/jsoncontent, the deserialized JSON object. This happens even if an error occurred. So if you get a 401 (Not Authorized) and the server sends a JSON object response with error info, you get that object back.
The bottom line is: You always need to check the
.lErrorflag or check the `. to ascertain whether the req
The URL to access the service method on the server
Optional - A FoxPro value or object or collection that is serialized to JSON and sent to the server
Optional - The HTTP Verb to use for this request (GET,POST,PUT,DELETE,HEAD,OPTIONS etc.). Default is GET if no data is sent or POST if lvData is not null or empty.
loProxy = CREATEOBJECT("wwJsonServiceClient") lcUrl = "http://albumviewer.west-wind.com/api/album" lvData = loAlbum && FoxPro object lcVerb = "PUT" && HTTP Verb *** Make the service call and returns an Album object loAlbum = loProxy.CallService(lcUrl,lvData,lcVerb) IF (loProxy.lError) ? loProxy.cErrorMsg RETURN ENDIF ? loAlbum.Title ? loAlbum.Artist.ArtistName
See also:Class wwJsonServiceClient
Comment or report problem with topic