Skip to content

VFPRestClient is a simple Microsoft XMLHTTP Object Wrapper for communicating with remote web services like API Rest.

Notifications You must be signed in to change notification settings

sixtored/VFPRestClient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VFPRestClient

VFPRestClient is a simple Microsoft XMLHTTP Object Wrapper for communicating client requests with remote web services like API Rest.

NOTE: you can combine this wrapper with JSONFox to complete the REST Client communications

Project Manager

Irwin Rodríguez (Toledo, Spain)

Latest Release

VFPRestClient - v.1.5 (beta) - Release 2019-04-09 14:17:51


Properties

  • LastErrorText: Stores the possible error generated in the current sentence.
  • Response: Stores the same content of ResponseText property.
  • ResponseText: Server's response. Inherited property from XMLHTTP Object.
  • Status: holds the HTTP Status Code. Inherited property from XMLHTTP Object.
  • StatusText: holds the HTTP Status Text. Inherited property from XMLHTTP Object.
  • ReadyState: current object state. Inherited property from XMLHTTP Object.

Methods

  • addRequest(tcVerb AS STRING, tcURL AS STRING): Adds a new Request.

    • tcVerb: Method used in request. You can use internal verb attributes as enum. eg. (loRest.GET, loRest.PUT, loRest.POST, etc)
    • tcURL: Remote server URL.
  • addHeader(tcHeader AS STRING, tcValue AS STRING): Adds a header to the request.

    • tcHeader: header type. You can use internal attribute as ENUM. eg. loRest.CONTENT_TYPE
    • tcValue: MIME type. You can use internal attribute as ENUM. eg. loRest.APPLICATION_JSON
  • addRequestBody(tcRequestBody AS STRING): Adds some data in Request Body optional.

    • tcRequestBody: request body (any data).
  • Send(): Send the request and RETURNS boolean.

    • Response attribute: either true or false. You can check the response property to see the server response.
  • Encode(vNewProp as variant): Encode a JSON object into string.

    • vNewProp: represents any value type.

Basic Usage

 // Create Object
 Set Procedure To "VFPRestClient.prg" Additive
 Public Rest
 Rest = NewObject("Rest", "VFPRestClient.prg")
 
 // Get planet with ID 1 from https://swapi.co
 Rest.AddRequest(Rest.GET, "https://swapi.co/api/planets/1/")
 
 // Don't forget check the LastErrorText
 If !Empty(Rest.LastErrorText) 
 	?Rest.LastErrorText, "Something went wrong"
	Release Rest
	Return
 EndIf
 
 // Send the request
 If Rest.Send()
     ?Rest.Response, "Success"
 Else
     ?Rest.Response, "Something went wrong"
 EndIf
 
Release Rest

About

VFPRestClient is a simple Microsoft XMLHTTP Object Wrapper for communicating with remote web services like API Rest.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • xBase 100.0%