Consuming RESTful Services in DataFlex: Difference between revisions
Consuming RESTful Services in DataFlex (view source)
Revision as of 18:23, 7 August 2019
, 7 August 2019Client
m (Cat) |
m (Client) |
||
Line 1: | Line 1: | ||
[[File:The RESTTest view.jpg|thumb|100px|The RESTTest view]] | [[File:The RESTTest view.jpg|thumb|100px|The RESTTest view]] | ||
To consume a web service we are going to need to be able to make HTTP requests and receive their responses. The way of doing this in DataFlex is by using the [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcHttpTransfer.htm cHttpTransfer class] (or its sub-classes: the [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcJsonHttpTransfer.htm cJsonHttpTransfer class] and the [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcXmlHttpTransfer.htm cXmlHttpTransfer class]). | To consume (be a client of) a web service we are going to need to be able to make HTTP requests and receive their responses. The way of doing this in DataFlex is by using the [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcHttpTransfer.htm cHttpTransfer class] (or its sub-classes: the [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcJsonHttpTransfer.htm cJsonHttpTransfer class] and the [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcXmlHttpTransfer.htm cXmlHttpTransfer class]). | ||
We will also want to make use of objects of the [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcJsonObject.htm&rhsearch=cJsonObject&rhhlterm=cJsonObject&rhsyns=%20 cJsonObject class] to handle responses and, in cases where we wish to create or update data, handle our request contents. | We will also want to make use of objects of the [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcJsonObject.htm&rhsearch=cJsonObject&rhhlterm=cJsonObject&rhsyns=%20 cJsonObject class] to handle responses and, in cases where we wish to create or update data, handle our request contents. | ||
Line 424: | Line 424: | ||
By default the view is set to call http://jsonplaceholder.typicode.com/posts (click that link to see the results you should get), which is a simple testing (somewhat) RESTful web service (you can use a path of "posts" - the default - "todos", "comments", "albums", "photos" or "users", and use POST, PUT, PATCH and DELETE, as well as the default GET - see http://jsonplaceholder.typicode.com for all the options). It supports both HTTP and HTTPS. Calls will not change anything, but do return sensible responses. It is useful for testing. | By default the view is set to call http://jsonplaceholder.typicode.com/posts (click that link to see the results you should get), which is a simple testing (somewhat) RESTful web service (you can use a path of "posts" - the default - "todos", "comments", "albums", "photos" or "users", and use POST, PUT, PATCH and DELETE, as well as the default GET - see http://jsonplaceholder.typicode.com for all the options). It supports both HTTP and HTTPS. Calls will not change anything, but do return sensible responses. It is useful for testing. | ||
To test other services, simply change the inputs to what | To test other services, simply change the inputs to what those require. | ||
==See also== | ==See also== |