A Simple RESTful Service: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
m
link & note on DD
m (DataFlex)
m (link & note on DD)
Line 585: Line 585:
You should be able to copy and paste this code to see it in operation, as follows:
You should be able to copy and paste this code to see it in operation, as follows:


Your workspace should contain the tables Customer (perhaps copied from the WebOrder sample) and WebAppUser.
Your workspace should contain the tables Customer (perhaps copied from the WebOrder sample) and WebAppUser. (You may find that if you have only copied the Data and DDSrc directories from the samples that you need to comment out the line "Use CustomerWebLookup.wo" in the cCustomerDataDictionary.dd file in order to get things to compile.)


If your workspace does not already have a WebApp, in the Studio use File --> New --> Project --> Basic Web Project to create one first. Then with the WebApp as the current project (selector top-left on the Studio tool-bar by default), use File --> New --> Web Object --> WebHttpHandler, calling the object '''oCustomerService'''; then select all (CTRL-A) and paste the code above over the existing contents.
If your workspace does not already have a WebApp, in the Studio use File --> New --> Project --> Basic Web Project (or Desktop Web Project, if you prefer) to create one first.


If you then compile and run the WebApp (F5), and change the URL in the web browser (Firefox is best for this, as it displays the returned JSON in the nicest format), replacing "Index.html" with "customerAPI" (the psPath setting in the code) you should see the output produced by the "ApiRoot" procedure, which will (at this point) have a single ''collection'': "customers". Clicking (in Firefox, at least) on the "href" value for that should then display a list of customers, each of which should in turn have an "href" element, clicking on which will take you to the details for that customer.
Then with the WebApp as the current project (selector top-left on the Studio tool-bar by default), use File --> New --> Web Object --> WebHttpHandler, calling the object '''oCustomerService'''; then select all (CTRL-A) and paste the code above over the existing contents.
 
If you then compile and run the WebApp (F5), and change the URL in the web browser (Firefox is best for this, as it displays the returned JSON in the nicest format), replacing "Index.html" with "customerAPI" (the psPath setting in the code) you should see the output produced by the "ApiRoot" procedure, which will (at this point) have a link to a single ''collection'': "customers". Clicking (in Firefox, at least) on the "href" value for that should then display a list of customers, each of which should in turn have an "href" element, clicking on which will take you to the details for that customer (the ''instance'').


To do more than simply display (i.e. GET) data, you will have to use a tool such as [https://www.getpostman.com/ Postman] (click the "Get Started" button, then the "Download" button, selecting the version - 32 or 64 bit - as appropriate for your machine, saving and then running the downloaded file) or the RESTTester tool detailed in the [[Consuming RESTful Services in DataFlex]] article.
To do more than simply display (i.e. GET) data, you will have to use a tool such as [https://www.getpostman.com/ Postman] (click the "Get Started" button, then the "Download" button, selecting the version - 32 or 64 bit - as appropriate for your machine, saving and then running the downloaded file) or the RESTTester tool detailed in the [[Consuming RESTful Services in DataFlex]] article.

Navigation menu