Giter Site home page Giter Site logo

vfprestclient's Introduction

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.

Examples

 * Create Object
 SET PROCEDURE TO "VFPRestClient.prg" ADDITIVE
 loREST = NEWOBJECT("Rest", "VFPRestClient.prg")
 
 * Get planet with ID 1 from https://swapi.co
 loRest.addRequest(loRest.GET, "https://swapi.co/api/planets/1/")
 
 * Don't forget check the LastErrorText
 IF !EMPTY(loRest.LastErrorText) 
 	MESSAGEBOX(loRest.LastErrorText, 0+48, "Something went wrong")
	RELEASE loRest
	RETURN
 ELSE &&!EMPTY(loRest.LastErrorText)
 ENDIF &&!EMPTY(loRest.LastErrorText)
 
 * Send the request
 IF loRest.Send()
 	MESSAGEBOX(loRest.Response, 64, "Success")
 ELSE &&loRest.Send()
 	MESSAGEBOX(loRest.Response, 48, "Something went wrong")
 ENDIF &&loRest.Send()
 
RELEASE loRest

vfprestclient's People

Contributors

irwin1985 avatar

Watchers

Tester avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.