Web Connection
Returning business objects in Json
Gravatar is a globally recognized avatar based on your email address. Returning business objects in Json
  Josh Klein
  All
  Oct 27, 2021 @ 07:06am

Looking for an example where my web server builds a hierarchical business object and returns this business object to the client using Json.

I have successfully returned json using a foxpro cursor by using:

return "cursor:myCursor"

Gravatar is a globally recognized avatar based on your email address. re: Returning business objects in Json
  Rick Strahl
  Josh Klein
  Oct 27, 2021 @ 11:46am

I recommend you take a look at this White Paper I just published. The second half of the paper deals with creating Web Connection REST APIs.

Building and Consuming REST API Services with FoxPro

The first part of the paper is also good if you're new to REST in general and some of the basic HTTP concepts as it introduces interacting with REST APIs from the client side, but the second part is specifically to Web Connection and REST services.

The short answer to your question is: You can return FoxPro objects. For a Business object you'd want to return either a cursor result (for a query method) or an object (the .oData member) or a you might want to build up an object and compose an object using CREATEOBJECT("EMPTY") plus ADDPROPERTY() to create complex nested objects and collections. You can also return cursors as child collections in the JSON. The white paper has examples of all of these.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Returning business objects in Json
  Josh Klein
  Rick Strahl
  Oct 27, 2021 @ 12:30pm

I can create the Json with the nested child properties. What I do not understand is how should the web server return the Json to the client?

Gravatar is a globally recognized avatar based on your email address. re: Returning business objects in Json
  Rick Strahl
  Josh Klein
  Oct 27, 2021 @ 03:44pm

If you're using a REST Service - which it looks like you're using - you just return the object from your method.

Read the white paper - it'll explain.

+++ Rick --

Gravatar is a globally recognized avatar based on your email address. re: Returning business objects in Json
  Josh Klein
  Rick Strahl
  Oct 29, 2021 @ 08:20am

Got it working by following your code in the Album Viewer MusicStore example. Thanks, Rick.

Josh

© 1996-2021